# !/usr/bin/python3
# _*_ coding: utf-8 _*_
# @Time     : 2022/3/29 下午7:53
# @Author   : HHR
# ___MSG___ : ""
import os, time, hashlib, base64, urllib.parse, imgkit, datetime
from docx import Document
from Administrative_office_system.settings import IS_TEST
from openpyxl import Workbook
from openpyxl.styles import Alignment, Font
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docx.shared import Cm,Pt, Inches
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_ALIGNMENT
from PyPDF4 import PdfFileReader, PdfFileWriter
import pythoncom
import comtypes.client
from django.db import connection
from bs4 import BeautifulSoup



def set_cell_border(cell, **kwargs):
    tc = cell._tc
    tcPr = tc.get_or_add_tcPr()

    tcBorders = tcPr.first_child_found_in("w:tcBorders")
    if tcBorders is None:
        tcBorders = OxmlElement('w:tcBorders')
        tcPr.append(tcBorders)

    for edge in ('left', 'top', 'right', 'bottom', 'insideH', 'insideV'):
        edge_data = kwargs.get(edge)
        if edge_data:
            tag = 'w:{}'.format(edge)

            element = tcBorders.find(qn(tag))
            if element is None:
                element = OxmlElement(tag)
                tcBorders.append(element)

            for key in ["sz", "val", "color", "space", "shadow"]:
                if key in edge_data:
                    element.set(qn('w:{}'.format(key)), str(edge_data[key]))



class select_mysql():
    def __init__(self):
        pass

    def select_data(self):
        select_meet_room_sql = "SELECT meeting_root, COUNT(*) FROM personal_center_conferenceroomapplication  where (TO_DAYS(NOW()) - TO_DAYS(statr_time)  <= 30) and (TO_DAYS(NOW()) - TO_DAYS(statr_time) >= 0) GROUP BY meeting_root"
        select_dep_sql = "SELECT department, COUNT(*) FROM personal_center_conferenceroomapplication  where (TO_DAYS(NOW()) - TO_DAYS(statr_time)  <= 30) and (TO_DAYS(NOW()) - TO_DAYS(statr_time) >= 0) GROUP BY department"
        meet_room_list, dep_list, meet_all_list, dep_all_dict = [], [], [], {}

        with connection.cursor() as cursor:
            cursor.execute(select_meet_room_sql)
            meet_room_list = cursor.fetchall()

            cursor.execute(select_dep_sql)
            dep_list = cursor.fetchall()

        for i in meet_room_list:
            one_dict = {}
            one_dict["value"] = i[1]
            one_dict["name"] = i[0]
            meet_all_list.append(one_dict)

        abscissa, ordinate = [], []
        for j in dep_list:
            abscissa.append(j[0])
            ordinate.append(j[1])

        dep_all_dict["abscissa"] = abscissa
        dep_all_dict["ordinate"] = ordinate
        return meet_all_list, dep_all_dict

    def Get_week(self, date_week):
        week = datetime.datetime.strptime(date_week, "%Y-%m-%d").weekday() + 1
        return week

    def select_iss(self):
        """查询议题统计"""
        select_dep_sql = "SELECT B.department, COUNT(*) FROM administrative_topics A LEFT JOIN tb_users_message B ON A.employee_id=B.id GROUP BY B.department"
        select_is_type = "SELECT (CASE type WHEN 'DB' THEN '党委会' WHEN 'YB' THEN '院长办公会' WHEN 'XZ' THEN '行政例会' END) `name`, COUNT(*) FROM administrative_topics WHERE YEAR(create_time)=YEAR(NOW()) GROUP BY `name`"
        type_all_list, dep_list, type_list, dep_all_dict = [], [], [], {}

        with connection.cursor() as cursor:
            cursor.execute(select_dep_sql)
            dep_list = cursor.fetchall()

            cursor.execute(select_is_type)
            type_list = cursor.fetchall()

        for i in type_list:
            one_dict = {}
            one_dict["value"] = i[1]
            one_dict["name"] = i[0]
            type_all_list.append(one_dict)

        abscissa, ordinate = [], []
        for j in dep_list:
            abscissa.append(j[0])
            ordinate.append(j[1])

        dep_all_dict["abscissa"] = abscissa
        dep_all_dict["ordinate"] = ordinate
        return type_all_list, dep_all_dict


class topic_directory():
    def __init__(self):
        pass

    def get_finished(self):
        """查询审批已完结议题"""
        select_sql = "SELECT C.id, C.type, C.update_time, C.topics_name, C.department, B.leaders FROM (SELECT A.id, A.type, A.update_time, A.topics_name, D.department, D.real_name FROM administrative_topics A LEFT JOIN tb_users_message D ON A.employee_id=D.id WHERE A.state='done' AND A.meetings_num='0') C LEFT JOIN administrative_company B ON C.department=B.`name`ORDER BY C.update_time ASC"
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            return cursor.fetchall()

    def search_xb(self, yt_id):
        """议题协办人员查询"""
        select_sql = f"SELECT (CASE WHEN f.director='' THEN f.deputy_director ELSE f.director END) '负责人' FROM (SELECT d.company_id director_id FROM administrative_topics c LEFT JOIN administrative_topics_help_department d ON c.id=d.topics_id WHERE c.id={yt_id}) e LEFT JOIN administrative_company f ON f.id=e.director_id"
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
        xb_people = ''
        if select_data:
            xb_people = ", ".join([i[0] for i in select_data if i[0]])
        return xb_people

    def dele_blank(self, file_path, pdf_path, file_name):
        path_output = pdf_path+f"/{file_name}.pdf"
        open_file = open(file_path, 'rb')
        reader = PdfFileReader(open_file)
        writer = PdfFileWriter()
        pages = reader.getNumPages()
        for i in range(pages):
            page = reader.getPage(i)
            try:
                if "/XObject" in page["/Resources"].keys() or "/Font" in page["/Resources"].keys():
                    writer.addPage(page)
            except:
                pass
        open_out_file = open(path_output, 'wb')
        writer.write(open_out_file)

        open_file.close()
        open_out_file.close()
        os.remove(file_path)
        return path_output

    def yb_func(self, one_dict, iss_type, file_name, dowload=False):
        if dowload:
            if "Y_D_leader" in one_dict["audit_dic"]:
                docx = Document(os.getcwd() + "/static/iss_model/院长办公会议题审批表副本_下载.docx")
            else:
                docx = Document(os.getcwd() + "/static/iss_model/院长办公会议题审批表副本.docx")
        else:
            if "Y_D_leader" in one_dict["audit_dic"]:
                docx = Document(os.getcwd() + "/static/iss_model/院长办公会议题审批表_新.docx")
            else:
                docx = Document(os.getcwd()+"/static/iss_model/院长办公会议题审批表.docx")
        tables = docx.tables
        table = tables[0]
        tjr = table.cell(2, 1).paragraphs[0].add_run(one_dict["tjr"])
        tjr.font.size = Pt(10)
        ks = table.cell(2, 3).paragraphs[0].add_run(one_dict["dep"])
        ks.font.size = Pt(10)
        ytbh = table.cell(2, 5).paragraphs[0].add_run(one_dict["ytbh"])
        ytbh.font.size = Pt(10)

        ytjs = table.cell(3, 1).paragraphs[0].add_run(one_dict["help_department"])
        ytjs.font.size = Pt(10)

        ysje = table.cell(3, 3).paragraphs[0].add_run(one_dict["ysje"])
        ysje.font.size = Pt(10)

        jfly = table.cell(3, 5).paragraphs[0].add_run(one_dict["jfly"])
        jfly.font.size = Pt(10)

        tjr = table.cell(4, 1).paragraphs[0].add_run(one_dict["title"])
        tjr.font.size = Pt(10)
        ks = table.cell(4, 5).paragraphs[0].add_run(one_dict["ygys"])
        ks.font.size = Pt(10)

        base_html = BeautifulSoup(urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["nrwb_base"]).decode()).decode()), 'lxml')

        table_list = base_html.select("table")
        if table_list:
            text_list = []
            for hh in table_list:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["nrwb"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number1 = 0
            nrwb_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(5, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list[table_number1].select("tr")
                    img_path = os.getcwd() + '/media/img/yb/nrwb'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\yb\nrwb'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list[table_number1]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png", options=options, config=cfg)
                    try:
                        if int(table_list[table_number1]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list[table_number1]["width"]) * 0.018
                    except:
                        width_number = 14
                    if width_number < 0:
                        width_number = 14
                    ysrun = table.cell(5, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number1 += 1
                nrwb_number += 1
            ytjs = table.cell(5, 1).paragraphs[-1].add_run('\n')
            ytjs.font.size = Pt(1)
        else:
            ytjs = table.cell(5, 1).paragraphs[0].add_run(one_dict["nrwb"])
            ytjs.font.size = Pt(10)

        base_html1 = BeautifulSoup(urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["zcyj_base"]).decode()).decode()), 'lxml')

        table_list1 = base_html1.select("table")
        if table_list1:
            text_list = []
            for hh in table_list1:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["zcyj"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number = 0
            zcyj_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(6, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list1[table_number].select("tr")
                    img_path = os.getcwd() + '/media/img/yb/zcyj'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\yb\zcyj'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list1[table_number]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list1[table_number]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list1[table_number]["width"]) * 0.018
                    except:
                        width_number = 14
                    ysrun = table.cell(6, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number += 1
                zcyj_number += 1
            zcyj = table.cell(6, 1).paragraphs[-1].add_run('\n')
            zcyj.font.size = Pt(1)
        else:
            zcyj = table.cell(6, 1).paragraphs[0].add_run(one_dict["zcyj"])
            zcyj.font.size = Pt(10)


        base_html2 = BeautifulSoup(urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["fawb_base"]).decode()).decode()), 'lxml')

        table_list2 = base_html2.select("table")
        if table_list2:
            text_list = []
            for hh in table_list2:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["fawb"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number = 0
            fawb_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(7, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list2[table_number].select("tr")
                    img_path = os.getcwd() + '/media/img/yb/fawb'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\yb\fawb'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list2[table_number]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list2[table_number]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list2[table_number]["width"]) * 0.018
                    except:
                        width_number = 14
                    ysrun = table.cell(7, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number += 1
                fawb_number += 1
            fawb = table.cell(7, 1).paragraphs[-1].add_run('\n')
            fawb.font.size = Pt(1)
        else:
            fawb = table.cell(7, 1).paragraphs[0].add_run(one_dict["fawb"])
            fawb.font.size = Pt(10)

        if "B" in one_dict["audit_dic"]:
            B_number = 0
            for i in one_dict["audit_dic"]["B"]:
                fgld = table.cell(9, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).merge(fgld.cell(0, 2))
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                if i['signature_picture']:
                    run = fgld.cell(1, 0).paragraphs[0].add_run()
                    picture = run.add_picture(i['signature_picture'])
                    picture.height = Cm(1.5)
                    picture.width = Cm(3)
                else:
                    fgld.cell(1, 0).paragraphs[0].add_run(i['audit_user'])
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if B_number != len(one_dict["audit_dic"]["B"]) - 1:
                    set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                B_number += 1

        if "Y_D_leader" not in one_dict["audit_dic"]:
            YB_DB_number = 0
            for t in one_dict["audit_dic"]["YB/DB"]:
                ybzr = table.cell(11, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                if t['signature_picture']:
                    zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                    zrpicture = zrrun.add_picture(t['signature_picture'])
                    zrpicture.height = Cm(1.5)
                    zrpicture.width = Cm(3)
                else:
                    ybzr.cell(1, 0).paragraphs[0].add_run(t['audit_user'])

                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YB_DB_number != len(one_dict["audit_dic"]["YB/DB"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YB_DB_number += 1

            orp_number = 0
            if "OPR" in one_dict["audit_dic"]:
                for t in one_dict["audit_dic"]["OPR"]:
                    ybzr = table.cell(10, 1).add_table(rows=2, cols=3)
                    ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                    ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                    ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                    if t['signature_picture']:
                        zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                        zrpicture = zrrun.add_picture(t['signature_picture'])
                        zrpicture.height = Cm(1.5)
                        zrpicture.width = Cm(3)
                    else:
                        ybzr.cell(1, 0).paragraphs[0].add_run(t['audit_user'])
                    ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                    ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if orp_number != len(one_dict["audit_dic"]["OPR"]) - 1:
                        set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    orp_number += 1

            YZ_SJ_number = 0
            for j in one_dict["audit_dic"]["YZ/SJ"]:
                yszr = table.cell(12, 1).add_table(rows=2, cols=3)
                yszr.cell(0, 0).paragraphs[0].add_run(j['state'])
                yszr.cell(0, 1).merge(yszr.cell(0, 2))
                yszr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
                if j['signature_picture']:
                    ysrun = yszr.cell(1, 0).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(j['signature_picture'])
                    yspicture.height = Cm(1.5)
                    yspicture.width = Cm(3)
                else:
                    yszr.cell(1, 0).paragraphs[0].add_run(j['audit_user'])
                yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YZ_SJ_number != len(one_dict["audit_dic"]["YZ/SJ"]) - 1:
                    set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YZ_SJ_number += 1

            if dowload and "yb_result" in one_dict["audit_dic"]:
                result_number = 0
                for j in one_dict["audit_dic"]["yb_result"]:
                    yszr = table.cell(12, 1).add_table(rows=3, cols=3)
                    state = j['audit_note'].split(';')[0]
                    audit_note = j['audit_note'].split(';')[1]
                    yszr.cell(0, 0).paragraphs[0].add_run(state)
                    yszr.cell(0, 0).merge(yszr.cell(0, 2))
                    yszr.cell(1, 0).paragraphs[0].add_run(audit_note)
                    yszr.cell(1, 0).merge(yszr.cell(1, 2))
                    yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                    yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if result_number != len(one_dict["audit_dic"]["yb_result"]) - 1:
                        set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    result_number += 1

        else:
            print("新流程")
            YB_DB_number = 0
            for t in one_dict["audit_dic"]["YB/DB"]:
                ybzr = table.cell(10, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                if t['signature_picture']:
                    zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                    zrpicture = zrrun.add_picture(t['signature_picture'])
                    zrpicture.height = Cm(1.5)
                    zrpicture.width = Cm(3)
                else:
                    ybzr.cell(1, 0).paragraphs[0].add_run(t['audit_user'])
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YB_DB_number != len(one_dict["audit_dic"]["YB/DB"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YB_DB_number += 1

            Yb_leader_number = 0
            for t in one_dict["audit_dic"]["Y_D_leader"]:
                ybzr = table.cell(11, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                if t['signature_picture']:
                    zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                    zrpicture = zrrun.add_picture(t['signature_picture'])
                    zrpicture.height = Cm(1.5)
                    zrpicture.width = Cm(3)
                else:
                    ybzr.cell(1, 0).paragraphs[0].add_run(t['audit_user'])
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if Yb_leader_number != len(one_dict["audit_dic"]["Y_D_leader"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                Yb_leader_number += 1

            YZ_SJ_number = 0
            for t in one_dict["audit_dic"]["YZ/SJ"]:
                ybzr = table.cell(12, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                if t['signature_picture']:
                    zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                    zrpicture = zrrun.add_picture(t['signature_picture'])
                    zrpicture.height = Cm(1.5)
                    zrpicture.width = Cm(3)
                else:
                    ybzr.cell(1, 0).paragraphs[0].add_run(t['audit_user'])
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YZ_SJ_number != len(one_dict["audit_dic"]["YZ/SJ"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YZ_SJ_number += 1

            if dowload and "yb_result" in one_dict["audit_dic"]:
                result_number = 0
                for j in one_dict["audit_dic"]["yb_result"]:
                    yszr = table.cell(13, 1).add_table(rows=3, cols=3)
                    state = j['audit_note'].split(';')[0]
                    audit_note = j['audit_note'].split(';')[1]
                    yszr.cell(0, 0).paragraphs[0].add_run(state)
                    yszr.cell(0, 0).merge(yszr.cell(0, 2))
                    yszr.cell(1, 0).paragraphs[0].add_run(audit_note)
                    yszr.cell(1, 0).merge(yszr.cell(1, 2))
                    yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                    yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if result_number != len(one_dict["audit_dic"]["yb_result"]) - 1:
                        set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    result_number += 1

        data = str(one_dict["ytbh"]+str(time.time()))
        file_hash = hashlib.sha1(data.encode("utf8")).hexdigest()
        path = os.getcwd() + f'/media/Issue_information/wordfile/{file_hash}'
        if not os.path.exists(path):
            os.makedirs(path)
        docx.save(path+f"/{file_name}.docx")
        pdf_path = os.getcwd() + f'/media/Issue_information/pdf_file/{iss_type}/{file_hash}'
        if not os.path.exists(pdf_path):
            os.makedirs(pdf_path)
        pythoncom.CoInitialize()
        word = comtypes.client.CreateObject("Word.Application")
        # pythoncom.CoInitialize()
        word.Visible = 0
        print(pdf_path+f"/{file_name}.pdf")
        newpdf = word.Documents.Open(path+f"/{file_name}.docx")
        newpdf.SaveAs(pdf_path+f"/{file_name}1.pdf", FileFormat=17)
        newpdf.Close(pdf_path+f"/{file_name}1.pdf")
        FilesPath = pdf_path+f"/{file_name}1.pdf"
        return self.dele_blank(FilesPath, pdf_path, file_name)

    def db_func(self, one_dict, iss_type, file_name, dowload=False):
        if "OPR" in one_dict["audit_dic"]:
            if dowload:
                docx = Document(os.getcwd() + "/static/iss_model/党委会议题审批表副本.docx")
            else:
                docx = Document(os.getcwd() + "/static/iss_model/党委会议题审批表.docx")
        else:
            docx = Document(os.getcwd() + "/static/iss_model/党委会议题审批表_直审.docx")
        tables = docx.tables
        table = tables[0]
        tjr = table.cell(2, 1).paragraphs[0].add_run(one_dict["tjr"])
        tjr.font.size = Pt(10)
        ks = table.cell(2, 3).paragraphs[0].add_run(one_dict["dep"])
        ks.font.size = Pt(10)
        ytbh = table.cell(2, 5).paragraphs[0].add_run(one_dict["ytbh"])
        ytbh.font.size = Pt(10)

        ytjs = table.cell(3, 1).paragraphs[0].add_run(one_dict["help_department"])
        ytjs.font.size = Pt(10)

        ysje = table.cell(3, 3).paragraphs[0].add_run(one_dict["ysje"])
        ysje.font.size = Pt(10)

        jfly = table.cell(3, 5).paragraphs[0].add_run(one_dict["jfly"])
        jfly.font.size = Pt(10)

        tjr = table.cell(4, 1).paragraphs[0].add_run(one_dict["title"])
        tjr.font.size = Pt(10)
        ks = table.cell(4, 5).paragraphs[0].add_run(one_dict["ygys"])
        ks.font.size = Pt(10)

        base_html = BeautifulSoup(
            urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["nrwb_base"]).decode()).decode()), 'lxml')

        table_list = base_html.select("table")
        if table_list:
            text_list = []
            for hh in table_list:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["nrwb"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number1 = 0
            nrwb_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(5, 1).paragraphs[0].add_run('\n')
                    zcyj = table.cell(5, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list[table_number1].select("tr")
                    img_path = os.getcwd() + '/media/img/db/nrwb'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\db\nrwb'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list[table_number1]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list[table_number1]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list[table_number1]["width"]) * 0.018
                    except:
                        width_number = 14
                    if width_number < 0:
                        width_number = 14
                    ysrun = table.cell(5, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number1 += 1
                nrwb_number += 1
            ytjs = table.cell(5, 1).paragraphs[-1].add_run('\n')
            ytjs.font.size = Pt(1)
        else:
            ytjs = table.cell(5, 1).paragraphs[0].add_run(one_dict["nrwb"])
            ytjs.font.size = Pt(10)

        base_html1 = BeautifulSoup(urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["zcyj_base"]).decode()).decode()), 'lxml')

        table_list1 = base_html1.select("table")
        if table_list1:
            text_list = []
            for hh in table_list1:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["zcyj"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number = 0
            zcyj_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    print(zcyj_number)
                    zcyj = table.cell(6, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list1[table_number].select("tr")
                    img_path = os.getcwd() + '/media/img/db/zcyj'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\db\zcyj'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list1[table_number]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list1[table_number]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list1[table_number]["width"]) * 0.018
                    except:
                        width_number = 14
                    ysrun = table.cell(6, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number += 1
                zcyj_number += 1
            zcyj = table.cell(6, 1).paragraphs[-1].add_run('\n')
            zcyj.font.size = Pt(1)
        else:
            zcyj = table.cell(6, 1).paragraphs[0].add_run(one_dict["zcyj"])
            zcyj.font.size = Pt(10)

        base_html2 = BeautifulSoup(
            urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["fawb_base"]).decode()).decode()), 'lxml')

        table_list2 = base_html2.select("table")
        if table_list2:
            text_list = []
            for hh in table_list2:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["fawb"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number = 0
            fawb_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(7, 1).paragraphs[0].add_run('\n'+ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list2[table_number].select("tr")
                    img_path = os.getcwd() + '/media/img/db/fawb'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\db\fawb'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list2[table_number]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list2[table_number]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list2[table_number]["width"]) * 0.018
                    except:
                        width_number = 14
                    ysrun = table.cell(7, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number += 1
                fawb_number += 1
            fawb = table.cell(7, 1).paragraphs[-1].add_run('\n')
            fawb.font.size = Pt(1)
        else:
            fawb = table.cell(7, 1).paragraphs[0].add_run(one_dict["fawb"])
            fawb.font.size = Pt(10)

        if "OPR" in one_dict["audit_dic"]:
            if "B" in one_dict["audit_dic"]:
                B_number = 0
                for i in one_dict["audit_dic"]["B"]:
                    fgld = table.cell(9, 1).add_table(rows=2, cols=3)
                    fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                    fgld.cell(0, 1).merge(fgld.cell(0, 2))
                    fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                    run = fgld.cell(1, 0).paragraphs[0].add_run()
                    picture = run.add_picture(i['signature_picture'])
                    picture.height = Cm(1.5)
                    picture.width = Cm(3)
                    fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                    fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if B_number != len(one_dict["audit_dic"]["B"]) - 1:
                        set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    B_number += 1

            OPR_number = 0
            for i in one_dict["audit_dic"]["OPR"]:
                if i['state'] == '同意':
                    status = "已审核"
                else:
                    status = i['state']
                fgld = table.cell(10, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(status)
                fgld.cell(0, 1).merge(fgld.cell(0, 2))
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                try:
                    run = fgld.cell(1, 0).paragraphs[0].add_run()
                    picture = run.add_picture(i['signature_picture'])
                    picture.height = Cm(1.5)
                    picture.width = Cm(3)
                    fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                    fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if OPR_number != len(one_dict["audit_dic"]["OPR"]) - 1:
                        set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                except:
                    pass
                OPR_number += 1

            YB_DB_number = 0
            for t in one_dict["audit_dic"]["YB/DB"]:
                if t['state'] == '同意':
                    status = "已审核"
                else:
                    status = t['state']
                ybzr = table.cell(11, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(status)
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                zrpicture = zrrun.add_picture(t['signature_picture'])
                zrpicture.height = Cm(1.5)
                zrpicture.width = Cm(3)
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YB_DB_number != len(one_dict["audit_dic"]["YB/DB"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YB_DB_number += 1

            YZ_SJ_number = 0
            for j in one_dict["audit_dic"]["YZ/SJ"]:
                yszr = table.cell(12, 1).add_table(rows=2, cols=3)
                yszr.cell(0, 0).paragraphs[0].add_run(j['state'])
                yszr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
                yszr.cell(0, 1).merge(yszr.cell(0, 2))
                ysrun = yszr.cell(1, 0).paragraphs[0].add_run()
                yspicture = ysrun.add_picture(j['signature_picture'])
                yspicture.height = Cm(1.5)
                yspicture.width = Cm(3)
                yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YZ_SJ_number != len(one_dict["audit_dic"]["YZ/SJ"]) - 1:
                    set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YZ_SJ_number += 1

            if "yb_result" in one_dict["audit_dic"]:
                result_number = 0
                for j in one_dict["audit_dic"]["yb_result"]:
                    yszr = table.cell(13, 1).add_table(rows=3, cols=3)
                    state = j['audit_note'].split(';')[0]
                    audit_note = j['audit_note']
                    yszr.cell(0, 0).paragraphs[0].add_run(state)
                    yszr.cell(0, 0).merge(yszr.cell(0, 2))
                    yszr.cell(1, 0).paragraphs[0].add_run(audit_note)
                    yszr.cell(1, 0).merge(yszr.cell(1, 2))
                    yszr.cell(2, 2).paragraphs[0].add_run(j['audit_time'])
                    yszr.cell(2, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if result_number != len(one_dict["audit_dic"]["yb_result"])-1:
                        set_cell_border(yszr.rows[2].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[2].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[2].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    result_number += 1

            if "transfer" in one_dict["audit_dic"]:
                transfer_number = 0
                for j in one_dict["audit_dic"]["transfer"]:
                    yszr = table.cell(14, 1).add_table(rows=3, cols=3)
                    yszr.cell(0, 0).paragraphs[0].add_run(j['audit_note'])
                    yszr.cell(0, 0).merge(yszr.cell(0, 2))
                    yszr.cell(2, 2).paragraphs[0].add_run(j['audit_time'])
                    yszr.cell(2, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if transfer_number != len(one_dict["audit_dic"]["transfer"])-1:
                        set_cell_border(yszr.rows[2].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[2].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[2].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    transfer_number += 1

            if "PG" in one_dict["audit_dic"]:
                PG_number = 0
                for j in one_dict["audit_dic"]["PG"]:
                    if j['state'] == '同意':
                        status = "已审核"
                    else:
                        status = j['state']
                    ybzr = table.cell(15, 1).add_table(rows=2, cols=3)
                    ybzr.cell(0, 0).paragraphs[0].add_run(status)
                    ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                    ybzr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
                    zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                    zrpicture = zrrun.add_picture(j['signature_picture'])
                    zrpicture.height = Cm(1.5)
                    zrpicture.width = Cm(3)
                    ybzr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                    ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if PG_number != len(one_dict["audit_dic"]["PG"])-1:
                        set_cell_border(ybzr.rows[2].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(ybzr.rows[2].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(ybzr.rows[2].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    PG_number += 1

            if "sj" in one_dict["audit_dic"]:
                sj_number = 0
                for j in one_dict["audit_dic"]["sj"]:
                    yszr = table.cell(17, 1).add_table(rows=2, cols=3)
                    yszr.cell(0, 0).paragraphs[0].add_run(j['state'])
                    yszr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
                    yszr.cell(0, 1).merge(yszr.cell(0, 2))
                    ysrun = yszr.cell(1, 0).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(j['signature_picture'])
                    yspicture.height = Cm(1.5)
                    yspicture.width = Cm(3)
                    yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                    yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if sj_number != len(one_dict["audit_dic"]["sj"]) - 1:
                        set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    sj_number += 1
        else:
            if "B" in one_dict["audit_dic"]:
                B_number = 0
                for i in one_dict["audit_dic"]["B"]:
                    fgld = table.cell(9, 1).add_table(rows=2, cols=3)
                    fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                    fgld.cell(0, 1).merge(fgld.cell(0, 2))
                    fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                    run = fgld.cell(1, 0).paragraphs[0].add_run()
                    picture = run.add_picture(i['signature_picture'])
                    picture.height = Cm(1.5)
                    picture.width = Cm(3)
                    fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                    fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                    if B_number != len(one_dict["audit_dic"]["B"]) - 1:
                        set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                        set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    B_number += 1

            YB_DB_number = 0
            for t in one_dict["audit_dic"]["YB/DB"]:
                if t['state'] == '同意':
                    status = "已审核"
                else:
                    status = t['state']
                ybzr = table.cell(10, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(status)
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                zrpicture = zrrun.add_picture(t['signature_picture'])
                zrpicture.height = Cm(1.5)
                zrpicture.width = Cm(3)
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YB_DB_number != len(one_dict["audit_dic"]["YB/DB"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YB_DB_number += 1

            leader_number = 0
            for t in one_dict["audit_dic"]["Y_D_leader"]:
                ybzr = table.cell(11, 1).add_table(rows=2, cols=3)
                ybzr.cell(0, 0).paragraphs[0].add_run(t['state'])
                ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
                ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
                zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
                zrpicture = zrrun.add_picture(t['signature_picture'])
                zrpicture.height = Cm(1.5)
                zrpicture.width = Cm(3)
                ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
                ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if leader_number != len(one_dict["audit_dic"]["Y_D_leader"]) - 1:
                    set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                leader_number += 1

            YZ_SJ_number = 0
            for j in one_dict["audit_dic"]["YZ/SJ"]:
                yszr = table.cell(12, 1).add_table(rows=2, cols=3)
                yszr.cell(0, 0).paragraphs[0].add_run(j['state'])
                yszr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
                yszr.cell(0, 1).merge(yszr.cell(0, 2))
                ysrun = yszr.cell(1, 0).paragraphs[0].add_run()
                yspicture = ysrun.add_picture(j['signature_picture'])
                yspicture.height = Cm(1.5)
                yspicture.width = Cm(3)
                yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
                yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                if YZ_SJ_number != len(one_dict["audit_dic"]["YZ/SJ"]) - 1:
                    set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                    set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                YZ_SJ_number += 1

        data = str(one_dict["ytbh"] + str(time.time()))
        file_hash = hashlib.sha1(data.encode("utf8")).hexdigest()
        path = os.getcwd() + f'/media/Issue_information/wordfile/{file_hash}'
        if not os.path.exists(path):
            os.makedirs(path)
        docx.save(path + f"/{file_name}.docx")
        pdf_path = os.getcwd() + f'/media/Issue_information/pdf_file/{iss_type}/{file_hash}'
        if not os.path.exists(pdf_path):
            os.makedirs(pdf_path)
        pythoncom.CoInitialize()
        word = comtypes.client.CreateObject("Word.Application")
        # pythoncom.CoInitialize()
        word.Visible = 0
        newpdf = word.Documents.Open(path + f"/{file_name}.docx")
        newpdf.SaveAs(pdf_path + f"/{file_name}1.pdf", FileFormat=17)
        newpdf.Close(pdf_path + f"/{file_name}1.pdf")
        FilesPath = pdf_path + f"/{file_name}1.pdf"
        return self.dele_blank(FilesPath, pdf_path, file_name)

    def xz_func(self, one_dict, iss_type, file_name, dowload=False):
        if dowload:
            docx = Document(os.getcwd() + "/static/iss_model/行政例会议题审批表副本.docx")
        else:
            docx = Document(os.getcwd() + "/static/iss_model/行政例会议题审批表.docx")
        tables = docx.tables
        table = tables[0]
        tjr = table.cell(2, 1).paragraphs[0].add_run(one_dict["tjr"])
        tjr.font.size = Pt(10)
        ks = table.cell(2, 3).paragraphs[0].add_run(one_dict["dep"])
        ks.font.size = Pt(10)
        ytbh = table.cell(2, 5).paragraphs[0].add_run(one_dict["ytbh"])
        ytbh.font.size = Pt(10)

        tjr = table.cell(3, 1).paragraphs[0].add_run(one_dict["title"])
        tjr.font.size = Pt(10)
        ks = table.cell(3, 5).paragraphs[0].add_run(one_dict["ygys"])
        ks.font.size = Pt(10)

        # ytjs = table.cell(4, 1).paragraphs[0].add_run(one_dict["help_department"])
        # ytjs.font.size = Pt(10)

        base_html = BeautifulSoup(urllib.parse.unquote(base64.b64decode(base64.b64decode(one_dict["nrwb_base"]).decode()).decode()), 'lxml')

        table_list = base_html.select("table")
        if table_list:
            text_list = []
            for hh in table_list:
                text_list.append(''.join([i.strip() for i in list(hh.text) if i.strip()]))

            text_str = ''.join([i.strip() for i in list(one_dict["nrwb"].strip()) if i.strip()])

            text_content_list = []
            for i in range(len(text_list) + 1):
                try:
                    one_list = text_str.split(text_list[i])
                    one_list.insert(1, text_list[i])
                    text_str = one_list[-1]
                    for t in one_list[:-1]:
                        if t.strip():
                            text_content_list.append(t)
                except:
                    text_content_list.append(text_str)

            table_number1 = 0
            nrwb_number = 0
            for ll in text_content_list:
                if ll.strip() not in text_list:
                    zcyj = table.cell(4, 1).paragraphs[0].add_run(ll)
                    zcyj.font.size = Pt(10)
                else:
                    tr_list1 = table_list[table_number1].select("tr")
                    img_path = os.getcwd() + '/media/img/xz/nrwb'
                    if not os.path.exists(img_path):
                        os.makedirs(img_path)
                    txt_path = os.getcwd() + r'\media\html_path\xz\nrwb'
                    if not os.path.exists(txt_path):
                        os.makedirs(txt_path)
                    with open(txt_path + r"\html_file.html", 'w', encoding="UTF-8") as f:
                        f.write(str(table_list[table_number1]))
                    if not IS_TEST:
                        path_wkimg = r"E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
                    else:
                        path_wkimg = r'D:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'  # 工具路径
                    cfg = imgkit.config(wkhtmltoimage=path_wkimg)
                    options = {
                        "encoding": "UTF-8"  # 这个具体要看你那个html页面到底是以什么编码格式保存的
                    }
                    imgkit.from_file(txt_path + r"\html_file.html", img_path + "imgs.png",
                                     options=options, config=cfg)
                    try:
                        if int(table_list[table_number1]["width"]) * 0.018 > 16:
                            width_number = 14
                        else:
                            width_number = int(table_list[table_number1]["width"]) * 0.018
                    except:
                        width_number = 14
                    ysrun = table.cell(4, 1).paragraphs[0].add_run()
                    yspicture = ysrun.add_picture(img_path + "imgs.png")
                    yspicture.height = Cm(len(tr_list1) * 0.7)
                    yspicture.width = Cm(width_number)
                    table_number1 += 1
                nrwb_number += 1
            ytjs = table.cell(4, 1).paragraphs[-1].add_run('\n')
            ytjs.font.size = Pt(1)
        else:
            ytjs = table.cell(4, 1).paragraphs[0].add_run(one_dict["nrwb"])
            ytjs.font.size = Pt(10)

        B_number = 0
        for i in one_dict["audit_dic"]["B"]:
            fgld = table.cell(6, 1).add_table(rows=2, cols=3)
            fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
            fgld.cell(0, 1).merge(fgld.cell(0, 2))
            fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
            run = fgld.cell(1, 0).paragraphs[0].add_run()
            picture = run.add_picture(i['signature_picture'])
            picture.height = Cm(1.5)
            picture.width = Cm(3)
            fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
            fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
            if B_number != len(one_dict["audit_dic"]["B"]) - 1:
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
            B_number += 1

        YB_DB_number = 0
        for t in one_dict["audit_dic"]["YB/DB"]:
            if t['state'] == '同意':
                status = "接收"
            else:
                status = "未接收"
            ybzr = table.cell(8, 1).add_table(rows=2, cols=3)
            ybzr.cell(0, 0).paragraphs[0].add_run(status)
            ybzr.cell(0, 1).merge(ybzr.cell(0, 2))
            ybzr.cell(0, 1).paragraphs[0].add_run(t['audit_note'])
            zrrun = ybzr.cell(1, 0).paragraphs[0].add_run()
            zrpicture = zrrun.add_picture(t['signature_picture'])
            zrpicture.height = Cm(1.5)
            zrpicture.width = Cm(3)
            ybzr.cell(1, 2).paragraphs[0].add_run(t['audit_time'])
            ybzr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
            if YB_DB_number != len(one_dict["audit_dic"]["YB/DB"]) - 1:
                set_cell_border(ybzr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(ybzr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(ybzr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
            YB_DB_number = 0

        YZ_SJ_number = 0
        for j in one_dict["audit_dic"]["YZ/SJ"]:
            yszr = table.cell(7, 1).add_table(rows=2, cols=3)
            yszr.cell(0, 0).paragraphs[0].add_run(j['state'])
            yszr.cell(0, 1).merge(yszr.cell(0, 2))
            yszr.cell(0, 1).paragraphs[0].add_run(j['audit_note'])
            ysrun = yszr.cell(1, 0).paragraphs[0].add_run()
            yspicture = ysrun.add_picture(j['signature_picture'])
            yspicture.height = Cm(1.5)
            yspicture.width = Cm(3)
            yszr.cell(1, 2).paragraphs[0].add_run(j['audit_time'])
            yszr.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
            if YZ_SJ_number != len(one_dict["audit_dic"]["YZ/SJ"]) - 1:
                set_cell_border(yszr.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(yszr.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(yszr.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
            YZ_SJ_number += 1

        data = str(time.time())
        file_hash = hashlib.sha1(data.encode("utf8")).hexdigest()
        path = os.getcwd() + f'/media/Issue_information/wordfile/{file_hash}'
        if not os.path.exists(path):
            os.makedirs(path)
        docx.save(path + f"/{file_name}.docx")
        pdf_path = os.getcwd() + f'/media/Issue_information/pdf_file/{iss_type}/{file_hash}'
        if not os.path.exists(pdf_path):
            os.makedirs(pdf_path)
        pythoncom.CoInitialize()
        word = comtypes.client.CreateObject("Word.Application")
        # pythoncom.CoInitialize()
        word.Visible = 0
        newpdf = word.Documents.Open(path + f"/{file_name}.docx")
        newpdf.SaveAs(pdf_path + f"/{file_name}1.pdf", FileFormat=17)
        newpdf.Close(pdf_path + f"/{file_name}1.pdf")
        FilesPath = pdf_path + f"/{file_name}1.pdf"
        return self.dele_blank(FilesPath, pdf_path, file_name)


    def main_fun(self):
        finished_data = self.get_finished()         # 已完结议题信息 不分类
        DbList, YbList, XzList = [], [], []
        for i in finished_data:
            if i[1] == "db":
                DbList.append(i)
            elif i[1] == "yb":
                YbList.append(i)
            else:
                XzList.append(i)

        DbDict = {}
        for t in DbList:
            if t[-2] in DbDict:
                db_one_list = DbDict[t[-2]]
                db_one_list.append(t)
                DbDict[t[-2]] = db_one_list
            else:
                DbDict[t[-2]] = [t]

        DbAllList = []
        for q in DbDict:
            for q1 in DbDict[q]:
                DbOneList = {}
                DbOneList["id"] = q1[0]
                DbOneList["time"] = str(q1[2]).split('.')[0][:-3]
                DbOneList["name"] = q1[3]
                DbOneList["dep"] = q1[4]
                DbOneList["cjr"] = q1[5]
                DbOneList["xbr"] = self.search_xb(q1[0])
                DbAllList.append(DbOneList)

        YbDict = {}
        for t in YbList:
            if t[-2] in YbDict:
                db_one_list = YbDict[t[-2]]
                db_one_list.append(t)
                YbDict[t[-2]] = db_one_list
            else:
                YbDict[t[-2]] = [t]

        YbAllList = []
        for q in YbDict:
            for q1 in YbDict[q]:
                YbOneList = {}
                YbOneList["id"] = q1[0]
                YbOneList["time"] = str(q1[2]).split('.')[0][:-3]
                YbOneList["name"] = q1[3]
                YbOneList["dep"] = q1[4]
                YbOneList["cjr"] = q1[5]
                YbOneList["xbr"] = self.search_xb(q1[0])
                YbAllList.append(YbOneList)

        XzDict = {}
        for t in XzList:
            if t[-2] in XzDict:
                db_one_list = XzDict[t[-2]]
                db_one_list.append(t)
                XzDict[t[-2]] = db_one_list
            else:
                XzDict[t[-2]] = [t]

        XzAllList = []
        for q in XzDict:
            for q1 in XzDict[q]:
                XzOneList = {}
                XzOneList["id"] = q1[0]
                XzOneList["time"] = str(q1[2]).split('.')[0][:-3]
                XzOneList["name"] = q1[3]
                XzOneList["dep"] = q1[4]
                XzOneList["cjr"] = q1[5]
                XzOneList["xbr"] = self.search_xb(q1[0])
                XzAllList.append(XzOneList)

        return DbAllList, YbAllList, XzAllList



class create_excel():
    def excel_write(self, insert_data, excel_name, excel_title):
        wb = Workbook()
        ws = wb['Sheet']
        ws.title = 'Sheet1'
        ws.merge_cells('A1:D1')
        top_left_cell = ws['A1']
        top_left_cell.value = f"{excel_title}"
        top_left_cell.font = Font(b=True, color="000000", size=16)
        top_left_cell.alignment = Alignment(horizontal="center", vertical="center")

        line_list = ["A2", "B2", "C2", "D2"]
        ws['A2'] = '议题名称'
        ws['B2'] = '汇报科室'
        ws['C2'] = '汇报人'
        ws['D2'] = '协办人'

        for line in line_list:
            top_left_cell = ws[line]
            top_left_cell.font = Font(b=True, color="000000", size=14)
            top_left_cell.alignment = Alignment(horizontal="center", vertical="center")
        row = 3
        serial = 1

        for x in insert_data:
            ws[f'A{row}'].alignment = Alignment(horizontal="center", vertical="center")
            ws[f'D{row}'].alignment = Alignment(horizontal="center", vertical="center")
            ws[f'E{row}'].alignment = Alignment(horizontal="center", vertical="center")
            ws[f'G{row}'].alignment = Alignment(horizontal="center", vertical="center")
            ws.cell(row, 1).value = x[3]
            ws.cell(row, 2).value = x[4]
            ws.cell(row, 3).value = x[5]
            ws.cell(row, 4).value = x[6]
            row += 1
        ws.column_dimensions['A'].width = 30
        ws.column_dimensions['B'].width = 20
        ws.column_dimensions['c'].width = 20
        ws.column_dimensions['D'].width = 30
        wb.save(excel_name)


class document_echarts():
    def __init__(self):
        pass

    def select_data(self):
        """查询各类公文当前年的数量"""
        select_sql = "SELECT type, COUNT(*) FROM administrative_conferencememo WHERE YEAR(create_time)=YEAR(NOW()) GROUP BY type"
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
        return select_data

    def select_dep(self):
        """当前年每月的数据统计"""
        dep_sql = "SELECT YEAR(create_time) AS year, MONTH(create_time) AS month, count(*) as count FROM administrative_conferencememo WHERE YEAR(create_time)=YEAR(NOW()) GROUP BY YEAR(create_time), MONTH(create_time)"
        with connection.cursor() as cursor:
            cursor.execute(dep_sql)
            select_data = cursor.fetchall()
        return select_data

    def main_fun(self):
        document_number = self.select_data()
        mount_number = self.select_dep()
        mouths = {'1': "一月", "2": "二月", "3": "三月", "4": "四月", "5": "五月", "6": "六月", "7": "七月", "8": "八月", "9": "九月", "10": "十月", "11": "十一月", "12": "十二月"}
        type_dict = {'a': "党委会纪要", "b": "院长办公会纪要", "c": "党委公会专题会议纪要", "d": "院长办公会专题会议纪要", "e": "行政例会简报", "f": "京医发", "g": "党委公文", "h": "京医文", "i": "共青团"}
        all_dict, mouth_list, mouth_val = {}, [], []
        for i in mount_number:
            mouth_list.append(mouths[str(i[1])])
            mouth_val.append(i[2])
        all_dict["mouth_list"] = mouth_list
        all_dict["mouth_val"] = mouth_val

        all_list = []
        for j in document_number:
            one_dict = {}
            one_dict["name"] = type_dict[j[0]]
            one_dict["value"] = j[1]
            all_list.append(one_dict)
        return all_dict, all_list


class document_pdf():
    def create_pdf(self, item, document_type):
        if document_type == 'a':
            model_file = os.getcwd()+"/static/document_domel/a.docx"
        elif document_type == 'b':
            model_file = os.getcwd() + "/static/document_domel/b.docx"
        elif document_type == 'c':
            model_file = os.getcwd() + "/static/document_domel/c.docx"
        elif document_type == 'd':
            model_file = os.getcwd() + "/static/document_domel/d.docx"
        elif document_type == 'e':
            model_file = os.getcwd() + "/static/document_domel/e.docx"
        elif document_type == 'f' or document_type == 'h':
            model_file = os.getcwd() + "/static/document_domel/f_h.docx"
        else:
            model_file = os.getcwd() + "/static/document_domel/g.docx"

        docx = Document(model_file)
        tables = docx.tables
        table = tables[0]
        tjr = table.cell(1, 1).paragraphs[0].add_run(item["department"])
        tjr.font.size = Pt(10)
        ks = table.cell(1, 3).paragraphs[0].add_run(item["apply_user"])
        ks.font.size = Pt(10)
        ytbh = table.cell(1, 5).paragraphs[0].add_run(item["document_number"])
        ytbh.font.size = Pt(10)

        tjr = table.cell(2, 1).paragraphs[0].add_run(item["conference_memo_text"])
        tjr.font.size = Pt(10)
        ks = table.cell(3, 1).paragraphs[0].add_run(item["main_company"])
        ks.font.size = Pt(10)

        ytjs = table.cell(4, 1).paragraphs[0].add_run(item["vice_company"])
        ytjs.font.size = Pt(10)

        if document_type in ["f", "h", "g"]:
            for i in item["audit_list"]["C/D"]:
                fgld = table.cell(6, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YB/DB"]:
                fgld = table.cell(7, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YBL/DBL"]:
                fgld = table.cell(8, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YZ/SJ"]:
                fgld = table.cell(9, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
        elif document_type in ["a", "b", "c", "d"]:
            for i in item["audit_list"]["YB/DB"]:
                fgld = table.cell(6, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YBL/DBL"]:
                fgld = table.cell(7, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["B"]:
                fgld = table.cell(8, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YZ/SJ"]:
                fgld = table.cell(9, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
        else:
            for i in item["audit_list"]["YB/DB"]:
                fgld = table.cell(6, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YBL/DBL"]:
                fgld = table.cell(7, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

            for i in item["audit_list"]["YZ/SJ"]:
                fgld = table.cell(8, 1).add_table(rows=2, cols=3)
                fgld.cell(0, 0).paragraphs[0].add_run(i['state'])
                fgld.cell(0, 1).paragraphs[0].add_run(i['audit_note'])
                run = fgld.cell(1, 0).paragraphs[0].add_run()
                picture = run.add_picture(os.getcwd()+i['signature_picture'])
                picture.height = Cm(1.5)
                picture.width = Cm(3)
                fgld.cell(1, 2).paragraphs[0].add_run(i['audit_time'])
                fgld.cell(1, 2).vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.BOTTOM
                set_cell_border(fgld.rows[1].cells[0], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[1], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})
                set_cell_border(fgld.rows[1].cells[2], bottom={"sz": 8, "val": "single", "color": "", "space": "0"})

        data = str(time.time())
        file_name = int(time.time())
        file_hash = hashlib.sha1(data.encode("utf8")).hexdigest()
        path = os.getcwd() + f'/media/Issue_information/wordfile/{file_hash}'
        if not os.path.exists(path):
            os.makedirs(path)
        docx.save(path + f"/{file_name}.docx")
        pdf_path = os.getcwd() + f'/media/Issue_information/pdf_file/dayin/{file_hash}'
        if not os.path.exists(pdf_path):
            os.makedirs(pdf_path)
        pythoncom.CoInitialize()
        word = comtypes.client.CreateObject("Word.Application")
        # pythoncom.CoInitialize()
        word.Visible = 0
        newpdf = word.Documents.Open(path + f"/{file_name}.docx")
        newpdf.SaveAs(pdf_path + f"/{file_name}.pdf", FileFormat=17)
        newpdf.Close(pdf_path + f"/{file_name}.pdf")
        return pdf_path + f"/{file_name}.pdf"


class manage_flow():
    """流程管理"""
    def my_audit(self, user_id, user_name):
        """我的待办"""
        # --         UNION ALL
        # --         SELECT '资产管理' AS Types, '物资采购' as classification, COUNT(productpurchase_id) counts FROM personal_center_productpurchase_current_audit_users WHERE user_id={user_id}
        # --         UNION ALL
        # --         SELECT '资产管理' AS Types, '物资领用' as classification, COUNT(productadopt_id) counts FROM personal_center_productadopt_current_audit_users WHERE user_id={user_id}

        select_sql = f"""
        SELECT * FROM (SELECT '公文管理' AS Types, '上级来文' AS classification, COUNT(id) counts FROM administrative_officialdocuments_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '外部来函' AS classification, COUNT(id) counts FROM administrative_correspondence_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '公告管理' AS Types, '通知公告' as classification, COUNT(notice_id) counts FROM announcements_notice_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '车辆管理' AS Types, '车辆申请' as classification, COUNT(id) counts FROM administrative_vehicleapply WHERE current_audit_user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '党委公文' as classification, COUNT(O.id) counts FROM administrative_conferencememo_current_audit_users O LEFT JOIN administrative_conferencememo P ON O.conferencememo_id=P.id WHERE O.user_id={user_id} AND P.type='g'
        UNION ALL
        SELECT '会议室管理' AS Types, '会议室申请' as classification, COUNT(id) counts FROM personal_center_conferenceroomapplication WHERE audit_people_id={user_id}
        UNION ALL
        SELECT '议题管理' AS Types, '党委会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='db' AND state!='shelve'
        UNION ALL
        SELECT '议题管理' AS Types, '行政例会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='xz' AND state!='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '党委会议纪要' as classification, COUNT(C.id) counts FROM administrative_conferencememo_current_audit_users C LEFT JOIN administrative_conferencememo D ON C.conferencememo_id=D.id WHERE C.user_id={user_id} AND D.type='a'
        UNION ALL
        SELECT '公文管理' AS Types, '行政例会简报' as classification, COUNT(K.id) counts FROM administrative_conferencememo_current_audit_users K LEFT JOIN administrative_conferencememo L ON K.conferencememo_id=L.id WHERE K.user_id={user_id} AND L.type='e'
        UNION ALL
        SELECT '议题管理' AS Types, '院长办公会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='yb' AND state!='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '党委专题会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_current_audit_users G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE G.user_id={user_id} AND H.type='c'
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医发)' as classification, COUNT(M.id) counts FROM administrative_conferencememo_current_audit_users M LEFT JOIN administrative_conferencememo N ON M.conferencememo_id=N.id WHERE M.user_id={user_id} AND N.type='f'
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医文)' as classification, COUNT(Q.id) counts FROM administrative_conferencememo_current_audit_users Q LEFT JOIN administrative_conferencememo R ON Q.conferencememo_id=R.id WHERE Q.user_id={user_id} AND R.type='h'
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会会议纪要' as classification, COUNT(E.id) counts FROM administrative_conferencememo_current_audit_users E LEFT JOIN administrative_conferencememo F ON E.conferencememo_id=F.id WHERE E.user_id={user_id} AND F.type='b'
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会专题会议纪要' as classification, COUNT(I.id) counts FROM administrative_conferencememo_current_audit_users I LEFT JOIN administrative_conferencememo J ON I.conferencememo_id=J.id WHERE I.user_id={user_id} AND J.type='d'
        UNION ALL
        SELECT '公文管理' AS Types, '京医团总支发文' as classification, COUNT(I.id) counts FROM administrative_conferencememo_current_audit_users I LEFT JOIN administrative_conferencememo J ON I.conferencememo_id=J.id WHERE I.user_id={user_id} AND J.type='i'
        UNION ALL
        SELECT '大型活动' AS Types, '大型活动报备' as classification, COUNT(I.id) counts FROM administrative_gatheringapply I LEFT JOIN administrative_gatheringapply_current_audit_users J ON J.gatheringapply_id=I.id WHERE J.user_id={user_id}
        UNION ALL
        SELECT '医德医风' AS Types, '医德医风考评' as classification, COUNT(id) counts FROM medical_ethics_evaluationofmedicalethics_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '用印审批' AS Types, '用印申请' as classification, COUNT(A.sealapply_id) counts FROM personal_center_sealapply_current_audit_users A LEFT JOIN personal_center_sealapply B ON A.sealapply_id=B.id WHERE user_id={user_id} AND B.state != 'shelve'
        UNION ALL
        SELECT '历史数据管理' AS Types, '固定资产/维修维保付款' as classification, COUNT(fixedassets_id) counts FROM personal_center_fixedassets_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅申请' as classification, COUNT(travelapply_id) counts FROM finance_travelapply_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '材料付款' as classification, COUNT(medicalmaterials_id) counts FROM finance_medicalmaterials_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '一般付款' as classification, COUNT(generalfinance_id) counts FROM finance_generalfinance_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '餐补付款' as classification, COUNT(nutritionalmeals_id) counts FROM finance_nutritionalmeals_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '新增医疗服务项目' as classification, COUNT(newmedicalservices_id) counts FROM finance_newmedicalservices_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '历史数据管理' AS Types, '合同付款' as classification, COUNT(logisticsoffice_id) counts FROM finance_logisticsoffice_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '人事审批' AS Types, '请假申请' as classification, COUNT(leaverequest_id) counts FROM finance_leaverequest_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '手术分级授权' as classification, COUNT(surgicalgrading_id) counts FROM finance_surgicalgrading_current_audit_users WHERE user_id={user_id}
         UNION ALL
        SELECT '临床管理' AS Types, '临床医师单独执业资格' as classification, COUNT(solopracticeapply_id) counts FROM finance_solopracticeapply_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '经济合同会签' as classification, COUNT(businesscontract_id) counts FROM finance_businesscontract_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅报销' as classification, COUNT(travelreimbursement_id) counts FROM finance_travelreimbursement_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '人事审批' AS Types, '离职申请' as classification, COUNT(dimission_id) counts FROM finance_dimission_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '差旅审批' AS Types, '中层干部外出' as classification, COUNT(outgoingcadresdata_id) counts FROM finance_outgoingcadresdata_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '历史数据管理' AS Types, '工会经费' as classification, COUNT(laborunionexpenses_id) counts FROM finance_laborunionexpenses_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '付款流程' as classification, COUNT(paymentapproval_id) counts FROM administrative_paymentapproval_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '经济合同会签流程' as classification, COUNT(contractapproval_id) counts FROM administrative_contractapproval_current_audit_users WHERE user_id={user_id}
        UNION ALL 
        SELECT '用印审批' AS Types, '印章刻制' as classification, COUNT(sealmaking_id) counts FROM finance_sealmaking_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '学科经费' as classification, COUNT(subjectfunding_id) counts FROM finance_subjectfunding_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '科研经费' as classification, COUNT(researchfunding_id) counts FROM finance_researchfunding_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '用印审批' AS Types, '快速用印授权' as classification, COUNT(quickauthorization_id) counts FROM finance_quickauthorization_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '图书/报刊/杂志征订' as classification, COUNT(booksubscription_id) counts FROM finance_booksubscription_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '党建经费' as classification, COUNT(partybuilding_id) counts FROM finance_partybuilding_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '项目审计送审申请' as classification, COUNT(objectaudit_id) counts FROM finance_objectaudit_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '服务采购' as classification, COUNT(purchasingrequisition_id) counts FROM logistics_purchasingrequisition_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '货物采购' as classification, COUNT(goodsprocure_id) counts FROM logistics_goodsprocure_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '维修改造' as classification, COUNT(maintenancerenovation_id) counts FROM logistics_maintenancerenovation_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '网络信息' AS Types, '计算机及相关设备购置' as classification, COUNT(computerdevice_id) counts FROM logistics_computerdevice_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '招标采购项目' as classification, COUNT(id) counts FROM logistics_biddingprocurementproject_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '招标结果汇报会签' as classification, COUNT(id) counts FROM logistics_tenderingsigning_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '会议室管理' AS Types, '短信审批' as classification, COUNT(id) counts FROM supervision_inspection_shortmessageapproval_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '流程节点修改' as classification, COUNT(id) counts FROM supervision_inspection_flowmodify_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '问责申请' as classification, COUNT(id) counts FROM supervision_inspection_initiateaccountability_current_audit_f16f WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '委员会议题' as classification, COUNT(id) counts FROM supervision_inspection_committeetopics_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '委员会纪要' as classification, COUNT(id) counts FROM supervision_inspection_committeeminutes_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '人事审批' AS Types, '行政总值班调班申请' as classification, COUNT(id) counts FROM supervision_inspection_shiftadjustment_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '会议室管理' AS Types, '会议请假' as classification, COUNT(id) counts FROM supervision_inspection_meetingroomleave_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '网络信息' AS Types, '数据外导' as classification, COUNT(id) counts FROM finance_confidentialdataexport_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '公务(外宾)接待事前审批' as classification, COUNT(id) counts FROM newflowlogic_beforehandreception_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '公务(外宾)接待清单审批' as classification, COUNT(id) counts FROM newflowlogic_receptionchecklist_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '职工出国(境)审批' as classification, COUNT(id) counts FROM newflowlogic_employeesabroad_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '基建维修改造' as classification, COUNT(id) counts FROM infrastructure_process_infrastructuremaintenance_current_aud18d7 WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '基建项目专业服务' as classification, COUNT(id) counts FROM infrastructure_process_professionalservices_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '体检科支援加班补助' as classification, COUNT(id) counts FROM payment_management_supportsubsidies_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会用印申请' as classification, COUNT(id) counts FROM union_process_officialseal_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会付款流程' as classification, COUNT(id) counts FROM union_process_paymentprocess_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会经济合同会签' as classification, COUNT(id) counts FROM union_process_economiccountersign_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会活动审批' as classification, COUNT(id) counts FROM union_process_eventapproval_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会物资申购' as classification, COUNT(id) counts FROM union_process_materialsapproval_current_audit_users WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '门诊排班调整' as classification, COUNT(id) counts FROM union_process_outpatientscheduling_current_audit_users WHERE user_id={user_id}
        ) Z ORDER BY counts DESC
        """
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()

        select_data = list(select_data)
        modul_sql = "SELECT id, module AS Types, `name` AS classification FROM system_setup_customerform"
        with connection.cursor() as cursor:
            cursor.execute(modul_sql)
            modul_data = cursor.fetchall()
            for modul in modul_data:
                bill_sql = f"SELECT '{modul[1]}' AS Types, '{modul[2]}' as classification, COUNT(A.id) counts FROM system_setup_lowcodebill_current_audit_users A LEFT JOIN system_setup_lowcodebill B ON A.lowcodebill_id=B.id WHERE user_id={user_id} AND B.customer_form_id={modul[0]}"
                with connection.cursor() as cursor:
                    cursor.execute(bill_sql)
                    bill_data = cursor.fetchall()
                    select_data.append(bill_data[0])
        return select_data

    def audit_post(self, user_id, user_name):
        """我的待办 POST 请求数据"""
        # UNION ALL
        # SELECT '物资领用' AS types, wzcg_zb.number as title, CONCAT(date_format(wzcg_zb.create_time, '%Y-%m-%d'), ' ', time_format(wzcg_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when wzcg_zb.state = 'two' then '结束' when wzcg_zb.state = 'four' then '退回' when wzcg_zb.state = 'cancel' then '作废' when wzcg_zb.state = 'stop' then '终止' when wzcg_zb.state = 'recall' then '撤回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('product_adopt_detail_view?id=', wzcg_zb.id) as url, case when wzcg_zb.state = 'four' then '修改' else '审批' END as `text` FROM personal_center_productpurchase_current_audit_users wzcg_sp LEFT JOIN personal_center_productadopt wzcg_zb ON wzcg_sp.productpurchase_id=wzcg_zb.id LEFT JOIN tb_users_message sq_user on wzcg_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on wzcg_sp.user_id=sp_user.id WHERE wzcg_sp.user_id={user_id}
        # UNION ALL
        # SELECT '物资采购' as types, wzly_zb.number as title, CONCAT(date_format(wzly_zb.create_time, '%Y-%m-%d'), ' ', time_format(wzly_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when wzly_zb.state = 'two' then '结束' when wzly_zb.state = 'four' then '退回' when wzly_zb.state = 'cancel' then '作废' when wzly_zb.state = 'stop' then '终止' when wzly_zb.state = 'recall' then '撤回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('product_shenpi_view?id=', wzly_zb.id) as url, case when wzly_zb.state = 'four' then '修改' else '审批' END as `text` FROM personal_center_productpurchase_current_audit_users wzly_sp LEFT JOIN personal_center_productpurchase wzly_zb ON wzly_sp.productpurchase_id=wzly_zb.id LEFT JOIN tb_users_message sq_user on wzly_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on wzly_sp.user_id=sp_user.id WHERE wzly_sp.user_id={user_id}
        select_sql = f"""
                SELECT * FROM (
                SELECT '上级来文' as types, a.title as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.type = 'd' then '传阅中' when a.type = 'e' then '完结' when a.type = 'f' then '退回' when a.type = 'g' then '待分发' else '审核中	' END as node, GROUP_CONCAT(DISTINCT au.real_name SEPARATOR ',') as approved, CONCAT('/personal-center/examinationDetail.html?approve=1&id=', a.id) as url, case when a.type = 'g' then '分发' when a.type = 'f' then '修改' else '审批' END as `text`, '1' as 'database' FROM administrative_officialdocuments a	INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id left join administrative_officialdocuments_current_audit_users m on m.officialdocuments_id = a.id LEFT JOIN tb_users_message au on m.user_id = au.id where au.id = {user_id} GROUP BY types, title, create_time, create_by, department, node, url, `text`
                UNION ALL
                SELECT '外部来函' AS types, a.title AS title, CONCAT(date_format( a.create_time, '%Y-%m-%d' ), ' ', time_format( a.create_time, '%H:%i' )) AS create_time, u.real_name AS create_by, c.`name` AS department, CASE WHEN a.type = 'four' THEN '传阅中' WHEN a.type = 'five' THEN '完结' WHEN a.type = 'six' THEN '退回' WHEN a.type = 'seven' THEN '待分发' ELSE '审核中	' END AS node, GROUP_CONCAT( DISTINCT au.real_name SEPARATOR ',' ) AS approved, CONCAT( '/personal-center/ExternalCorrespondenceDetail.html?approve=1&id=', a.id ) AS url, CASE WHEN a.type = 'seven' THEN '分发' WHEN a.type = 'six' THEN '修改' ELSE '审批' END AS `text`, '1' AS 'database' FROM administrative_correspondence a INNER JOIN tb_users_message u ON a.apply_user_id = u.id INNER JOIN administrative_company c ON u.company_id = c.id LEFT JOIN administrative_correspondence_current_audit_users m ON m.correspondence_id = a.id LEFT JOIN tb_users_message au ON m.user_id = au.id WHERE au.id = {user_id} GROUP BY types, title, create_time, create_by, department, node, url, `text` 
	            UNION ALL
                SELECT '通知公告' AS types, tzgg_zb.`name` AS title, CONCAT(date_format( tzgg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( tzgg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN tzgg_zb.state = 'end' THEN '结束' WHEN tzgg_zb.state = 'eight' THEN '退回' WHEN tzgg_zb.state = 'stop' THEN '终止' ELSE '审核中' END AS node, sp_user.real_name AS approved, CASE WHEN tzgg_zb.state = 'eight' THEN CONCAT( '/announcements/notice_change.html?id=', tzgg_zb.id ) ELSE CONCAT('/announcements/notice_approve.html?id=', tzgg_zb.id) END AS url, CASE WHEN tzgg_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '17' AS 'database' FROM announcements_notice_current_audit_users tzgg_sp LEFT JOIN announcements_notice tzgg_zb ON tzgg_sp.notice_id = tzgg_zb.id LEFT JOIN tb_users_message sq_user ON tzgg_zb.create_people_id = sq_user.id LEFT JOIN tb_users_message sp_user ON tzgg_sp.user_id = sp_user.id WHERE tzgg_sp.user_id ={ user_id }
                UNION ALL
                SELECT '车辆管理' AS types, a.`subject` as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'cgb' then '完结' when a.state = 'done' then '完结' when a.state = 'refuse' then '退回' when a.state = 'cancel' then '作废' else '审核中' END as node, au.real_name as approved, CONCAT('/personal-center/Vehicle_apply_detail.html?id=', a.id) as url, case when a.state = 'refuse' then '修改' else '审批' END as `text`, '3' as 'database' FROM administrative_vehicleapply a INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id LEFT JOIN tb_users_message au on au.id = a.current_audit_user_id where a.current_audit_user_id = {user_id}
                UNION ALL
                SELECT (case when a.type = 'db' then '党委会议题' when a.type = 'yb' then '院长办公会议题' when a.type = 'xz' then '行政例会议题' END) as types, a.topics_name as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'done' then '完结' when a.state = 'unmetting' then '待上会' when a.state = 'metting' then '已上会' when a.state = 'shelve' then '搁置' when a.state = 'refuse' then '退回' when a.state = 'cancel' then '作废' when a.state = 'stop' then '终止' when a.state = 'recall' then '撤回' else '审核中' END as node, a.current_audit_user as approved, case when a.state = 'refuse' then CONCAT('Issue_modify.html?id=', a.id) else CONCAT('/personal-center/SubjectDetailst.html?id=', a.id) END as url, case when a.state = 'refuse' then '修改' else '审批' END as `text`, '4' as 'database' FROM administrative_topics a INNER JOIN tb_users_message u on a.employee_id = u.id INNER JOIN administrative_company c on a.company_id = c.id where a.current_audit_user = '{user_name}' AND a.state != 'shelve'
                UNION ALL
                SELECT (case when a.type = 'a' then '党委会议纪要' when a.type = 'b' then '院长办公会会议纪要' when a.type = 'c' then '党委专题会议纪要' when a.type = 'd' then '院长办公会专题会议纪要' when a.type = 'e' then '行政例会简报' when a.type = 'f' then '京医发' when a.type = 'g' then '党委公文' when a.type = 'h' then '京医文' WHEN a.type = 'i' THEN '京医团总支发文' END) as types, a.conference_memo_text as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'six' then '退回' when a.state = 'seven' then '完结' when a.state = 'eight' then '待分发' when a.state = 'nine' then '审核中' when a.state = 'stop' then '终止' when a.state = 'draft' then '草稿' when a.state = 'cancel' then '作废' when a.state = 'recall' then '撤回' else '审核中' END as node, GROUP_CONCAT(DISTINCT au.real_name SEPARATOR ',') as approved, case when a.state = 'six' then CONCAT('refer_back.html?id=', a.id) else CONCAT('/personal-center/document_approve.html?id=', a.id) END as url, case when a.state = 'six' then '修改' when a.state = 'eight' then '分发' else '审批' END as `text`, '5' as 'database' FROM administrative_conferencememo a INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id left join administrative_conferencememo_current_audit_users m on m.conferencememo_id = a.id LEFT JOIN tb_users_message au on m.user_id = au.id where au.id = {user_id} GROUP BY types, title, create_time, create_by, department, node, url, `text`
                UNION ALL
                SELECT '会议室申请' as types, a.meeting_root as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, a.names as create_by, a.department as department, case when a.state = 'audit' then '完结' when a.state = 'revoke' then '撤销' else '审核中' END as node, u.real_name as approved, CONCAT('/personal-center/conference_room_detail?id=', a.id) as url, '审批' as `text`, '6' as 'database' FROM personal_center_conferenceroomapplication a left join tb_users_message u on a.audit_people_id = u.id where a.audit_people_id = {user_id} GROUP BY types, title, create_time, create_by, department, node, url, `text`
                UNION ALL
                SELECT '大型活动报备' as types, hdbbzb.gathering_note as title, CONCAT(date_format(hdbbzb.create_time, '%Y-%m-%d'), ' ', time_format(hdbbzb.create_time, '%H:%i')) as create_time, sp_user.real_name as create_by, sp_user.department as department, case when hdbbzb.state = 'three' then '拒绝' when hdbbzb.state = 'cancel' then '作废' when hdbbzb.state = 'stop' then '终止' when hdbbzb.state = 'recall' then '撤回' when hdbbzb.state = 'five' then '完结' else '审核中' END as node, user_table.real_name as approved, CONCAT('/administrative/gathering_apply_detail_view?id=', hdbbzb.id) as url, case when hdbbzb.state = 'three' then '修改' else '审批' END as `text`, '7' as 'database' FROM administrative_gatheringapply_current_audit_users hdbbpb LEFT JOIN administrative_gatheringapply hdbbzb ON hdbbpb.gatheringapply_id=hdbbzb.id LEFT JOIN tb_users_message user_table on hdbbpb.user_id=user_table.id LEFT JOIN tb_users_message sp_user on hdbbzb.apply_user_id=sp_user.id WHERE hdbbpb.user_id={user_id}
                UNION ALL
                SELECT '医德医风考评' AS types, ydyfzb.title AS title, CONCAT(date_format( ydyfzb.create_time, '%Y-%m-%d' ), ' ', time_format( ydyfzb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, CASE WHEN ydyfzb.apply_company_id = "1001" THEN '医德医风评选一组' WHEN ydyfzb.apply_company_id = "1002" THEN '医德医风评选二组' WHEN ydyfzb.apply_company_id = "1003" THEN '医德医风评选三组' WHEN ydyfzb.apply_company_id = "1004" THEN '医德医风评选四组' ELSE my_com.`name` END AS department, CASE WHEN ydyfzb.state = 'five' THEN '结束' WHEN ydyfzb.state = 'six' THEN '撤回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/medical-ethics/medical_ethics_detail_view?id=', ydyfzb.id ) AS url, '审批' AS `text`, '8' AS 'database' FROM medical_ethics_evaluationofmedicalethics_current_audit_users ydyfpb LEFT JOIN medical_ethics_evaluationofmedicalethics ydyfzb ON ydyfpb.evaluationofmedicalethics_id = ydyfzb.id LEFT JOIN tb_users_message sq_user ON ydyfzb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ydyfpb.user_id = sp_user.id LEFT JOIN administrative_company my_com ON ydyfzb.apply_company_id = my_com.id WHERE ydyfpb.user_id = {user_id}
                UNION ALL
                SELECT case when yyspzb.is_fast = 1 then '快捷用印申请' else '用印申请' END as types, yyspzb.matter_type_text as title, CONCAT(date_format(yyspzb.create_time, '%Y-%m-%d'), ' ', time_format(yyspzb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yyspzb.state = 'five' then '结束' when yyspzb.state = 'six' then '退回' when yyspzb.state = 'cancel' then '作废' when yyspzb.state = 'stop' then '终止' when yyspzb.state = 'recall' then '撤回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/seal_apply_detail_view?id=', yyspzb.id) as url, case when yyspzb.state = 'six' then '修改' else '审批' END as `text`, '9' as 'database' FROM personal_center_sealapply_current_audit_users yysqsp LEFT JOIN personal_center_sealapply yyspzb ON yysqsp.sealapply_id=yyspzb.id LEFT JOIN tb_users_message sq_user on yyspzb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yysqsp.user_id=sp_user.id WHERE yysqsp.user_id={user_id} AND yyspzb.state != 'shelve'
                UNION ALL
                SELECT '固定资产/维修维保付款' as types,fksq_zb.title as title, CONCAT(date_format(fksq_zb.create_time, '%Y-%m-%d'), ' ', time_format(fksq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when fksq_zb.state = 'six' then '结束' when fksq_zb.state = 'seven' then '退回' when fksq_zb.state = 'cancel' then '作废' when fksq_zb.state = 'stop' then '终止' when fksq_zb.state = 'recall' then '撤回' when fksq_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/fixed_assets_apply_detail_view?id=', fksq_zb.id) as url, case when fksq_zb.state = 'seven' then '修改' else '审批' END as `text`, '10' as 'database' FROM personal_center_fixedassets_current_audit_users fksq_sp LEFT JOIN personal_center_fixedassets fksq_zb ON fksq_sp.fixedassets_id =fksq_zb.id LEFT JOIN tb_users_message sq_user on fksq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on fksq_sp.user_id=sp_user.id WHERE fksq_sp.user_id={user_id}
                UNION ALL
                SELECT '差旅申请' as types, clsq_zb.subject as title, CONCAT(date_format(clsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(clsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clsq_zb.state = 'five' then '结束' when clsq_zb.state = 'eight' then '退回' when clsq_zb.state = 'cancel' then '作废' when clsq_zb.state = 'stop' then '终止' when clsq_zb.state = 'recall' then '撤回' when clsq_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/travel_apply_detail_view?id=', clsq_zb.id) as url, case when clsq_zb.state = 'eight' then '修改' else '审批' END as `text`, '11' as 'database' FROM finance_travelapply_current_audit_users clsq_sp LEFT JOIN finance_travelapply clsq_zb ON clsq_sp.travelapply_id=clsq_zb.id LEFT JOIN tb_users_message sq_user on clsq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on clsq_sp.user_id=sp_user.id WHERE clsq_sp.user_id={user_id}
                UNION ALL
                SELECT '差旅报销' as types, clbx_zb.business_matter as title, CONCAT(date_format(clbx_zb.create_time, '%Y-%m-%d'), ' ', time_format(clbx_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clbx_zb.state = 'seven' then '结束' when clbx_zb.state = 'eight' then '退回' when clbx_zb.state = 'cancel' then '作废' when clbx_zb.state = 'stop' then '终止' when clbx_zb.state = 'recall' then '撤回' when clbx_zb.state = 'draft' then '草稿' when clbx_zb.state = 'six' then '待付款' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/travel_approval.html?id=', clbx_zb.id) as url, case when clbx_zb.state = 'eight' then '修改' else '审批' END as `text`, '12' as 'database' FROM finance_travelreimbursement_current_audit_users clbx_sp LEFT JOIN finance_travelreimbursement clbx_zb ON clbx_sp.travelreimbursement_id=clbx_zb.id LEFT JOIN tb_users_message sq_user on clbx_zb.applicat_id=sq_user.id LEFT JOIN tb_users_message sp_user on clbx_sp.user_id=sp_user.id WHERE clbx_sp.user_id={user_id}
                UNION ALL
                SELECT '经济合同会签' as types, jjht_zb.contract_name as title, CONCAT(date_format(jjht_zb.create_time, '%Y-%m-%d'), ' ', time_format(jjht_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when jjht_zb.state = 'seven' then '结束' when jjht_zb.state = 'eight' then '退回' when jjht_zb.state = 'cancel' then '作废' when jjht_zb.state = 'stop' then '终止' when jjht_zb.state = 'recall' then '撤回' when jjht_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/business_contract_detail_view?id=', jjht_zb.id) as url, case when jjht_zb.state = 'eight' then '修改' else '审批' END as `text`, '13' as 'database' FROM finance_businesscontract_current_audit_users jjht_sp LEFT JOIN finance_businesscontract jjht_zb ON jjht_sp.businesscontract_id=jjht_zb.id LEFT JOIN tb_users_message sq_user on jjht_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on jjht_sp.user_id=sp_user.id WHERE jjht_sp.user_id={user_id}
                UNION ALL
                SELECT '材料付款' as types, clfk_zb.title as title, CONCAT(date_format(clfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(clfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clfk_zb.state = 'seven' then '结束' when clfk_zb.state = 'eight' then '退回' when clfk_zb.state = 'cancel' then '作废' when clfk_zb.state = 'stop' then '终止' when clfk_zb.state = 'recall' then '撤回' when clfk_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/medical_materials_detail_view?id=', clfk_zb.id) as url, case when clfk_zb.state = 'eight' then '修改' else '审批' END as `text`, '14' as 'database' FROM finance_medicalmaterials_current_audit_users clfk_sp LEFT JOIN finance_medicalmaterials clfk_zb ON clfk_sp.medicalmaterials_id=clfk_zb.id LEFT JOIN tb_users_message sq_user on clfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on clfk_sp.user_id=sp_user.id WHERE clfk_sp.user_id={user_id}
                UNION ALL
                SELECT '合同付款' as types, htfk_zb.pay_reason as title, CONCAT(date_format(htfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(htfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when htfk_zb.state = 'seven' then '结束' when htfk_zb.state = 'eight' then '退回' when htfk_zb.state = 'cancel' then '作废' when htfk_zb.state = 'stop' then '终止' when htfk_zb.state = 'recall' then '撤回' when htfk_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/logistics_office_apply_detail_view?id=', htfk_zb.id) as url, case when htfk_zb.state = 'eight' then '修改' else '审批' END as `text`, '15' as 'database' FROM finance_logisticsoffice_current_audit_users htfk_sp LEFT JOIN finance_logisticsoffice htfk_zb ON htfk_sp.logisticsoffice_id=htfk_zb.id LEFT JOIN tb_users_message sq_user on htfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on htfk_sp.user_id=sp_user.id WHERE htfk_sp.user_id={user_id}
                UNION ALL
                SELECT '餐补付款' as types, yykfk_zb.title as title, CONCAT(date_format(yykfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(yykfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yykfk_zb.state = 'seven' then '结束' when yykfk_zb.state = 'eight' then '退回' when yykfk_zb.state = 'cancel' then '作废' when yykfk_zb.state = 'stop' then '终止' when yykfk_zb.state = 'recall' then '撤回' when yykfk_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/nutritional_meals_detail_view?id=', yykfk_zb.id) as url, case when yykfk_zb.state = 'eight' then '修改' else '审批' END as `text`, '16' as 'database' FROM finance_nutritionalmeals_current_audit_users yykfk_sp LEFT JOIN finance_nutritionalmeals yykfk_zb ON yykfk_sp.nutritionalmeals_id=yykfk_zb.id LEFT JOIN tb_users_message sq_user on yykfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yykfk_sp.user_id=sp_user.id WHERE yykfk_sp.user_id={user_id}
                UNION ALL
                SELECT '一般付款' as types, cgfk_zb.title as title, CONCAT(date_format(cgfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(cgfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when cgfk_zb.state = 'seven' then '结束' when cgfk_zb.state = 'eight' then '退回' when cgfk_zb.state = 'cancel' then '作废' when cgfk_zb.state = 'stop' then '终止' when cgfk_zb.state = 'recall' then '撤回' when cgfk_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/general_finance_detail_view?id=', cgfk_zb.id) as url, case when cgfk_zb.state = 'eight' then '修改' else '审批' END as `text`, '17' as 'database' FROM finance_generalfinance_current_audit_users cgfk_sp LEFT JOIN finance_generalfinance cgfk_zb ON cgfk_sp.generalfinance_id=cgfk_zb.id LEFT JOIN tb_users_message sq_user on cgfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on cgfk_sp.user_id=sp_user.id WHERE cgfk_sp.user_id={user_id}
                UNION ALL
                SELECT '付款流程' AS types, fklc_zb.title AS title, CONCAT(date_format( fklc_zb.create_time, '%Y-%m-%d' ), ' ', time_format( fklc_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_com.`name` AS department, CASE WHEN fklc_zb.state = 'end' THEN '结束' WHEN fklc_zb.state = 'eight' THEN '退回' WHEN fklc_zb.state = 'stop' THEN '终止' WHEN fklc_zb.state = 'recall' THEN '撤回' WHEN fklc_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/payment_process_detail.html?id=', fklc_zb.id ) AS url, CASE WHEN fklc_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '17' AS 'database' FROM administrative_paymentapproval_current_audit_users fklc_sp LEFT JOIN administrative_paymentapproval fklc_zb ON fklc_sp.paymentapproval_id = fklc_zb.id LEFT JOIN tb_users_message sq_user ON fklc_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON fklc_sp.user_id = sp_user.id LEFT JOIN administrative_company sq_com ON fklc_zb.company_id=sq_com.id WHERE fklc_sp.user_id ={ user_id }
                UNION ALL
                SELECT '经济合同会签流程' AS types, hthq_zb.title AS title, CONCAT(date_format( hthq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( hthq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN hthq_zb.state = 'end' THEN '结束' WHEN hthq_zb.state = 'eight' THEN '退回' WHEN hthq_zb.state = 'stop' THEN '终止' WHEN hthq_zb.state = 'recall' THEN '撤回' WHEN hthq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/ContractDetail.html?id=', hthq_zb.id ) AS url, CASE WHEN hthq_zb.state = 'eight' THEN	'修改' ELSE '审批' 	END AS `text`, '17' AS 'database' FROM	administrative_contractapproval_current_audit_users hthq_sp	LEFT JOIN administrative_contractapproval hthq_zb ON hthq_sp.contractapproval_id = hthq_zb.id	LEFT JOIN tb_users_message sq_user ON hthq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hthq_sp.user_id = sp_user.id WHERE hthq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '请假申请' as types, qjsq_zb.reason as title, CONCAT(date_format(qjsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(qjsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when qjsq_zb.state = 'seven' then '结束' when qjsq_zb.state = 'eight' then '退回' when qjsq_zb.state = 'cancel' then '作废' when qjsq_zb.state = 'stop' then '终止' when qjsq_zb.state = 'recall' then '撤回' when qjsq_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/leave_request_detail_view?id=', qjsq_zb.id) as url, case when qjsq_zb.state = 'eight' then '修改' else '审批' END as `text`, '18' as 'database' FROM finance_leaverequest_current_audit_users qjsq_sp LEFT JOIN finance_leaverequest qjsq_zb ON qjsq_sp.leaverequest_id=qjsq_zb.id LEFT JOIN tb_users_message sq_user on qjsq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on qjsq_sp.user_id=sp_user.id WHERE qjsq_sp.user_id={user_id}
                UNION ALL
                SELECT '离职申请' as types, lzsq_zb.dimission_note as title, CONCAT(date_format(lzsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(lzsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when lzsq_zb.state = 'seven' then '结束' when lzsq_zb.state = 'eight' then '退回' when lzsq_zb.state = 'cancel' then '作废' when lzsq_zb.state = 'stop' then '终止' when lzsq_zb.state = 'recall' then '撤回' when lzsq_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/dimission_detail_view?id=', lzsq_zb.id) as url, case when lzsq_zb.state = 'eight' then '修改' else '审批' END as `text`, '19' as 'database' FROM finance_dimission_current_audit_users lzsq_sp LEFT JOIN finance_dimission lzsq_zb ON lzsq_sp.dimission_id=lzsq_zb.id LEFT JOIN tb_users_message sq_user on lzsq_zb.user_id=sq_user.id LEFT JOIN tb_users_message sp_user on lzsq_sp.user_id=sp_user.id WHERE lzsq_sp.user_id={user_id}
                UNION ALL
                SELECT '新增医疗服务项目' as types, xzyl_zb.title as title, CONCAT(date_format(xzyl_zb.create_time, '%Y-%m-%d'), ' ', time_format(xzyl_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when xzyl_zb.state = 'seven' then '结束' when xzyl_zb.state = 'eight' then '退回' when xzyl_zb.state = 'cancel' then '作废' when xzyl_zb.state = 'stop' then '终止' when xzyl_zb.state = 'recall' then '撤回' when xzyl_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/new_medical_services_detail_view?id=', xzyl_zb.id) as url, case when xzyl_zb.state = 'eight' then '修改' else '审批' END as `text`, '20' as 'database' FROM finance_newmedicalservices_current_audit_users xzyl_sp LEFT JOIN finance_newmedicalservices xzyl_zb ON xzyl_sp.newmedicalservices_id=xzyl_zb.id LEFT JOIN tb_users_message sq_user on xzyl_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on xzyl_sp.user_id=sp_user.id WHERE xzyl_sp.user_id={user_id}
                UNION ALL
                SELECT '手术分级授权' as types, shfq_zb.reason as title, CONCAT(date_format(shfq_zb.create_time, '%Y-%m-%d'), ' ', time_format(shfq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when shfq_zb.state = 'seven' then '结束' when shfq_zb.state = 'eight' then '退回' when shfq_zb.state = 'cancel' then '作废' when shfq_zb.state = 'stop' then '终止' when shfq_zb.state = 'recall' then '撤回' when shfq_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/surgical_grading_detail_view?id=', shfq_zb.id) as url, case when shfq_zb.state = 'eight' then '修改' else '审批' END as `text`, '21' as 'database' FROM finance_surgicalgrading_current_audit_users shfq_sp LEFT JOIN finance_surgicalgrading shfq_zb ON shfq_sp.surgicalgrading_id=shfq_zb.id LEFT JOIN tb_users_message sq_user on shfq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on shfq_sp.user_id=sp_user.id WHERE shfq_sp.user_id={user_id}
                UNION ALL
                SELECT '临床医师单独执业资格' as types, lcys_zb.doctor_qualified_number as title, CONCAT(date_format(lcys_zb.create_time, '%Y-%m-%d'), ' ', time_format(lcys_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when lcys_zb.state = 'seven' then '结束' when lcys_zb.state = 'eight' then '退回' when lcys_zb.state = 'cancel' then '作废' when lcys_zb.state = 'stop' then '终止' when lcys_zb.state = 'recall' then '撤回' when lcys_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/solo_practice_apply_detail_view?id=', lcys_zb.id) as url, case when lcys_zb.state = 'eight' then '修改' else '审批' END as `text`, '22' as 'database' FROM finance_solopracticeapply_current_audit_users lcys_sp LEFT JOIN finance_solopracticeapply lcys_zb ON lcys_sp.solopracticeapply_id=lcys_zb.id LEFT JOIN tb_users_message sq_user on lcys_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on lcys_sp.user_id=sp_user.id WHERE lcys_sp.user_id={user_id}
                UNION ALL
                SELECT '中层干部外出' as types, zcgb_zb.title as title, CONCAT(date_format(zcgb_zb.create_time, '%Y-%m-%d'), ' ', time_format(zcgb_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, cc.`name` as department, case when zcgb_zb.state = 'seven' then '结束' when zcgb_zb.state = 'eight' then '退回' when zcgb_zb.state = 'cancel' then '作废' when zcgb_zb.state = 'stop' then '终止' when zcgb_zb.state = 'recall' then '撤回' when zcgb_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/middle_level_detail.html?id=', zcgb_zb.id) as url, case when zcgb_zb.state = 'eight' then '修改' else '审批' END as `text`, '23' as 'database' FROM finance_outgoingcadresdata_current_audit_users zcgb_sp LEFT JOIN finance_outgoingcadresdata zcgb_zb ON zcgb_sp.outgoingcadresdata_id=zcgb_zb.id LEFT JOIN tb_users_message sq_user on zcgb_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on zcgb_sp.user_id=sp_user.id LEFT JOIN administrative_company cc ON sp_user.company_id=cc.id WHERE zcgb_sp.user_id={user_id}
                UNION ALL
                SELECT '工会经费' as types, ghjf_zb.pay_reason as title, CONCAT(date_format(ghjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(ghjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when ghjf_zb.state = 'seven' then '结束' when ghjf_zb.state = 'eight' then '退回' when ghjf_zb.state = 'cancel' then '作废' when ghjf_zb.state = 'stop' then '终止' when ghjf_zb.state = 'recall' then '撤回' when ghjf_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/LaborUnionExpensesdetail.html?id=', ghjf_zb.id) as url, case when ghjf_zb.state = 'eight' then '修改' else '审批' END as `text`, '24' as 'database' FROM finance_laborunionexpenses_current_audit_users ghjf_sp LEFT JOIN finance_laborunionexpenses ghjf_zb ON ghjf_sp.laborunionexpenses_id=ghjf_zb.id LEFT JOIN tb_users_message sq_user on ghjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on ghjf_sp.user_id=sp_user.id WHERE ghjf_sp.user_id={user_id}
                UNION ALL
                SELECT '印章刻制' as types,yzkz_zb.plan_seal_name as title, CONCAT(date_format(yzkz_zb.create_time, '%Y-%m-%d'), ' ', time_format(yzkz_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yzkz_zb.state = 'seven' then '结束' when yzkz_zb.state = 'eight' then '退回' when yzkz_zb.state = 'cancel' then '作废' when yzkz_zb.state = 'stop' then '终止' when yzkz_zb.state = 'recall' then '撤回' when yzkz_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/seal_making_detail_view?id=', yzkz_zb.id) as url, case when yzkz_zb.state = 'eight' then '修改' else '审批' END as `text`, '25' as 'database' FROM finance_sealmaking_current_audit_users yzkz_sp LEFT JOIN finance_sealmaking yzkz_zb ON yzkz_sp.sealmaking_id=yzkz_zb.id LEFT JOIN tb_users_message sq_user on yzkz_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yzkz_sp.user_id=sp_user.id WHERE yzkz_sp.user_id={user_id}
                UNION ALL
                SELECT '学科经费' as types,ghjf_zb.pay_reason as title, CONCAT(date_format(ghjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(ghjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when ghjf_zb.state = 'seven' then '结束' when ghjf_zb.state = 'eight' then '退回' when ghjf_zb.state = 'cancel' then '作废' when ghjf_zb.state = 'stop' then '终止' when ghjf_zb.state = 'recall' then '撤回' when ghjf_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/subject_funding_detail.html?id=', ghjf_zb.id) as url, case when ghjf_zb.state = 'eight' then '修改' else '审批' END as `text`, '26' as 'database' FROM finance_subjectfunding_current_audit_users ghjf_sp LEFT JOIN finance_subjectfunding ghjf_zb ON ghjf_sp.subjectfunding_id=ghjf_zb.id LEFT JOIN tb_users_message sq_user on ghjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on ghjf_sp.user_id=sp_user.id WHERE ghjf_sp.user_id={user_id}
                UNION ALL
                SELECT '科研经费' as types, kyjf_zb.pay_reason as title, CONCAT(date_format(kyjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(kyjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when kyjf_zb.state = 'seven' then '结束' when kyjf_zb.state = 'eight' then '退回' when kyjf_zb.state = 'cancel' then '作废' when kyjf_zb.state = 'stop' then '终止' when kyjf_zb.state = 'recall' then '撤回' when kyjf_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/research_funding_detail.html?id=', kyjf_zb.id) as url, case when kyjf_zb.state = 'eight' then '修改' else '审批' END as `text`, '31' as 'database' FROM finance_researchfunding_current_audit_users kyjf_sp LEFT JOIN finance_researchfunding kyjf_zb ON kyjf_sp.researchfunding_id=kyjf_zb.id LEFT JOIN tb_users_message sq_user on kyjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on kyjf_sp.user_id=sp_user.id WHERE kyjf_sp.user_id={user_id}
                UNION ALL
                SELECT '快速用印授权' AS types, TRIM('"' FROM AA.titles->'$.neirong') AS title, CONCAT(date_format( ksyy_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ksyy_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ksyy_zb.state = 'seven' THEN '结束' WHEN ksyy_zb.state = 'eight' THEN '退回' WHEN ksyy_zb.state = 'stop' THEN '终止' WHEN ksyy_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/QuickAuthorizationDetail.html?id=', ksyy_zb.id ) AS url, CASE WHEN ksyy_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '27' AS 'database' FROM finance_quickauthorization_current_audit_users ksyy_sp LEFT JOIN finance_quickauthorization ksyy_zb ON ksyy_sp.quickauthorization_id = ksyy_zb.id LEFT JOIN tb_users_message sq_user ON ksyy_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ksyy_sp.user_id = sp_user.id LEFT JOIN (SELECT JSON_EXTRACT(reason, "$[0]") titles, id FROM finance_quickauthorization) AA ON ksyy_zb.id=AA.id WHERE ksyy_sp.user_id = {user_id}
                UNION ALL
                SELECT '图书/报刊/杂志征订' as types, '图书/报刊/杂志征订申请' as title, CONCAT(date_format(tsbk_zb.create_time, '%Y-%m-%d'), ' ', time_format(tsbk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when tsbk_zb.state = 'seven' then '结束' when tsbk_zb.state = 'eight' then '退回' when tsbk_zb.state = 'stop' then '终止' when tsbk_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/BookSubscriptionDetail.html?id=', tsbk_zb.id) as url, case when tsbk_zb.state = 'eight' then '修改' else '审批' END as `text`, '28' as 'database' FROM finance_booksubscription_current_audit_users tsbk_sp LEFT JOIN finance_booksubscription tsbk_zb ON tsbk_sp.booksubscription_id=tsbk_zb.id LEFT JOIN tb_users_message sq_user on tsbk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on tsbk_sp.user_id=sp_user.id WHERE tsbk_sp.user_id={user_id}
                UNION ALL
                SELECT '党建经费' as types, REPLACE((CASE WHEN djjf_zb.application_reason != '' THEN djjf_zb.application_reason WHEN JSON_EXTRACT (`pay_detail` -> '$[0]', '$.b') != '' THEN JSON_EXTRACT (`pay_detail` -> '$[0]', '$.b') ELSE '党建经费' END), '"', '') AS title, CONCAT(date_format(djjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(djjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when djjf_zb.state = 'seven' then '结束' when djjf_zb.state = 'eight' then '退回' when djjf_zb.state = 'stop' then '终止' when djjf_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/PartyBuildingFundsDetail.html?id=', djjf_zb.id) as url, case when djjf_zb.state = 'eight' then '修改' else '审批' END as `text`, '29' as 'database' FROM finance_partybuilding_current_audit_users djjf_sp LEFT JOIN finance_partybuilding djjf_zb ON djjf_sp.partybuilding_id=djjf_zb.id LEFT JOIN tb_users_message sq_user on djjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on djjf_sp.user_id=sp_user.id WHERE djjf_sp.user_id={user_id}
                UNION ALL
                SELECT zdy_wj.module as types, zdy_wj.`name` as title, CONCAT(date_format(zdy_zb.create_time, '%Y-%m-%d'), ' ', time_format(zdy_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when zdy_zb.state = 'two' then '结束' when zdy_zb.state = 'four' then '退回' when zdy_zb.state = 'three' then '终止' when zdy_zb.state = 'draft' then '草稿' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/CustomProcessDetail.html?id=', zdy_zb.id) as url, case when zdy_zb.state = 'four' then '修改' else '审批' END as `text`, '30' as 'database' FROM system_setup_lowcodebill_current_audit_users zdy_sp LEFT JOIN system_setup_lowcodebill zdy_zb ON zdy_sp.lowcodebill_id=zdy_zb.id LEFT JOIN tb_users_message sq_user on zdy_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on zdy_sp.user_id=sp_user.id LEFT JOIN system_setup_customerform zdy_wj ON zdy_zb.customer_form_id=zdy_wj.id WHERE zdy_sp.user_id={user_id}
                UNION ALL
                SELECT '项目审计送审申请' AS types, djjf_zb.work_name AS title, CONCAT(date_format( djjf_zb.create_time, '%Y-%m-%d' ), ' ', time_format( djjf_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN djjf_zb.state = 'seven' THEN '结束' WHEN djjf_zb.state = 'eight' THEN '退回' WHEN djjf_zb.state = 'stop' THEN '终止' WHEN djjf_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/object_audit_detail_view?id=', djjf_zb.id ) AS url, CASE WHEN djjf_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM finance_objectaudit_current_audit_users djjf_sp LEFT JOIN finance_objectaudit djjf_zb ON djjf_sp.objectaudit_id = djjf_zb.id LEFT JOIN tb_users_message sq_user ON djjf_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON djjf_sp.user_id = sp_user.id WHERE djjf_sp.user_id={user_id}
                UNION ALL
                SELECT '招标结果汇报会签' AS types, zbhq_zb.entry_name AS title, CONCAT(date_format( zbhq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( zbhq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zbhq_zb.state = 'end' THEN '结束' WHEN zbhq_zb.state = 'eight' THEN '退回' WHEN zbhq_zb.state = 'stop' THEN '终止' WHEN zbhq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/tendering_signing_detail.html?id=', zbhq_zb.id ) AS url, CASE WHEN zbhq_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '47' AS 'database' FROM logistics_tenderingsigning_current_audit_users zbhq_sp LEFT JOIN logistics_tenderingsigning zbhq_zb ON zbhq_sp.tenderingsigning_id = zbhq_zb.id LEFT JOIN tb_users_message sq_user ON zbhq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zbhq_sp.user_id = sp_user.id WHERE zbhq_sp.user_id ={ user_id }
                UNION ALL
                SELECT "科室考勤确认" AS types, "科室考勤确认" AS title, CONCAT(date_format( kqtj_zb.create_time, '%Y-%m-%d' ), ' ', time_format( kqtj_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN kqtj_zb.state = 'END' THEN '结束' ELSE '审核中' END AS node, sp_user.real_name AS approved, CASE WHEN kqtj_zb.state = 'one' THEN '/personnel/attendance.html' ELSE '/personnel/AttendanceStatistics.html' END AS url, '审批' AS `text`, '31' AS 'database' FROM finance_checkworktable_current_audit_users kqtj_sp LEFT JOIN finance_checkworktable kqtj_zb ON kqtj_sp.checkworktable_id = kqtj_zb.id LEFT JOIN tb_users_message sq_user ON kqtj_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON kqtj_sp.user_id = sp_user.id WHERE kqtj_sp.user_id={user_id}
                UNION ALL
                SELECT '服务采购' AS types, fwcg_zb.ApplicationReason AS title, CONCAT(date_format( fwcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( fwcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN fwcg_zb.state = 'seven' THEN '结束' WHEN fwcg_zb.state = 'six' THEN '退回' WHEN fwcg_zb.state = 'stop' THEN '终止' WHEN fwcg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/ServiceProcurementDetail.html?id=', fwcg_zb.id ) AS url, CASE WHEN fwcg_zb.state = 'six' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM logistics_purchasingrequisition_current_audit_users fwcg_sp LEFT JOIN logistics_purchasingrequisition fwcg_zb ON fwcg_sp.purchasingrequisition_id = fwcg_zb.id LEFT JOIN tb_users_message sq_user ON fwcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON fwcg_sp.user_id = sp_user.id WHERE fwcg_sp.user_id={user_id}
                UNION ALL
                SELECT '货物采购' AS types, CONCAT(hwcg_zb.GoodsName, '(', hwcg_zb.GoodsNumber, ')', '<br>', hwcg_zb.PurchaseReason) AS title, CONCAT(date_format(hwcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format(hwcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN hwcg_zb.state = 'seven' THEN '结束' WHEN hwcg_zb.state = 'six' THEN '退回' WHEN hwcg_zb.state = 'stop' THEN '终止' WHEN hwcg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/GoodsProcureDetail.html?id=', hwcg_zb.id ) AS url, CASE WHEN hwcg_zb.state = 'six' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM logistics_goodsprocure_current_audit_users hwcg_sp LEFT JOIN logistics_goodsprocure hwcg_zb ON hwcg_sp.goodsprocure_id = hwcg_zb.id LEFT JOIN tb_users_message sq_user ON hwcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hwcg_sp.user_id = sp_user.id WHERE hwcg_sp.user_id={user_id}
                UNION ALL
				SELECT '计算机及相关设备购置' AS types, jsjcg_zb.ApplicationReason AS title, CONCAT(date_format(jsjcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format(jsjcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jsjcg_zb.state = 'seven' THEN '结束' WHEN jsjcg_zb.state = 'six' THEN '退回' WHEN jsjcg_zb.state = 'stop' THEN '终止' WHEN jsjcg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/ComputerDeviceDetail.html?id=', jsjcg_zb.id ) AS url, CASE WHEN jsjcg_zb.state = 'six' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM logistics_computerdevice_current_audit_users jsjcg_sp LEFT JOIN logistics_computerdevice jsjcg_zb ON jsjcg_sp.computerdevice_id = jsjcg_zb.id LEFT JOIN tb_users_message sq_user ON jsjcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jsjcg_sp.user_id = sp_user.id WHERE jsjcg_sp.user_id ={ user_id }
                UNION ALL
                SELECT '招标采购项目' AS types, zbcg_zb.ApplicationReason AS title, CONCAT(date_format( zbcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( zbcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zbcg_zb.state = 'seven' THEN '结束' WHEN zbcg_zb.state = 'eight' THEN '退回' WHEN zbcg_zb.state = 'stop' THEN '终止' WHEN zbcg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/BiddingProcurementProjectDetail.html?id=', zbcg_zb.id ) AS url, CASE WHEN zbcg_zb.state = 'eight' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM logistics_biddingprocurementproject_current_audit_users zbcg_sp LEFT JOIN logistics_biddingprocurementproject zbcg_zb ON zbcg_sp.biddingprocurementproject_id = zbcg_zb.id LEFT JOIN tb_users_message sq_user ON zbcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zbcg_sp.user_id = sp_user.id WHERE zbcg_sp.user_id ={ user_id }
                UNION ALL
                SELECT '短信审批' AS types, dxsp_zb.reason AS title, CONCAT(date_format( dxsp_zb.create_time, '%Y-%m-%d' ), ' ', time_format( dxsp_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN dxsp_zb.state = 'end' THEN '结束' WHEN dxsp_zb.state = 'refuse' THEN '退回' WHEN dxsp_zb.state = 'stop' THEN '终止' WHEN dxsp_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/message_approval_detail.html?id=', dxsp_zb.id ) AS url, CASE WHEN dxsp_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '40' AS 'database' FROM supervision_inspection_shortmessageapproval_current_audit_users dxsp_sp LEFT JOIN supervision_inspection_shortmessageapproval dxsp_zb ON dxsp_sp.shortmessageapproval_id = dxsp_zb.id LEFT JOIN tb_users_message sq_user ON dxsp_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON dxsp_sp.user_id = sp_user.id WHERE dxsp_sp.user_id ={ user_id }
                UNION ALL
                SELECT '问责申请' AS types, CONCAT('工作督办问责流程', '(', work_table.job_source, ')') AS title, CONCAT(date_format( wzsq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wzsq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, '审核中' AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/accountability_detail.html?id=', wzsq_zb.id ) AS url, '审批' AS `text`, '40' AS 'database' FROM supervision_inspection_initiateaccountability_current_audit_f16f wzsq_sp LEFT JOIN supervision_inspection_initiateaccountability wzsq_zb ON wzsq_sp.initiateaccountability_id = wzsq_zb.id LEFT JOIN supervision_inspection_worksupervisehandle work_table ON wzsq_zb.work_id_id = work_table.id LEFT JOIN tb_users_message sq_user ON wzsq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wzsq_sp.user_id = sp_user.id WHERE wzsq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '流程节点修改' AS types, jdxg_zb.reason AS title, CONCAT(date_format( jdxg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jdxg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jdxg_zb.state = 'end' THEN '结束' WHEN jdxg_zb.state = 'refuse' THEN '退回' WHEN jdxg_zb.state = 'stop' THEN '终止' WHEN jdxg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/process_modification_detail.html?id=', jdxg_zb.id ) AS url, CASE WHEN jdxg_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '40' AS 'database' FROM supervision_inspection_flowmodify_current_audit_users jdxg_sp LEFT JOIN supervision_inspection_flowmodify jdxg_zb ON jdxg_sp.flowmodify_id = jdxg_zb.id LEFT JOIN tb_users_message sq_user ON jdxg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jdxg_sp.user_id = sp_user.id WHERE jdxg_sp.user_id ={ user_id }
                UNION ALL
                SELECT '委员会议题' AS types, wyhyt_zb.topic_name AS title, CONCAT(date_format( wyhyt_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wyhyt_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wyhyt_zb.state = 'end' THEN '结束' WHEN wyhyt_zb.state = 'refuse' THEN '退回' WHEN wyhyt_zb.state = 'stop' THEN '终止' WHEN wyhyt_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CASE WHEN wyhyt_zb.state = 'refuse' THEN CONCAT( '/supervision-inspection/committee_topics_modify.html?id=', wyhyt_zb.id ) ELSE CONCAT( '/supervision-inspection/committee_topics_detail.html?id=', wyhyt_zb.id ) END AS url, CASE WHEN wyhyt_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '40' AS 'database' FROM supervision_inspection_committeetopics_current_audit_users wyhyt_sp LEFT JOIN supervision_inspection_committeetopics wyhyt_zb ON wyhyt_sp.committeetopics_id = wyhyt_zb.id LEFT JOIN tb_users_message sq_user ON wyhyt_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wyhyt_sp.user_id = sp_user.id WHERE wyhyt_sp.user_id ={ user_id }
                UNION ALL
                SELECT '委员会纪要' AS types, wyhjy_zb.conference_memo_text AS title, CONCAT(date_format( wyhjy_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wyhjy_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wyhjy_zb.state = 'end' THEN '结束' WHEN wyhjy_zb.state = 'refuse' THEN '退回' WHEN wyhjy_zb.state = 'stop' THEN '终止' WHEN wyhjy_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/summary_application_detail.html?id=', wyhjy_zb.id ) AS url, CASE WHEN wyhjy_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '40' AS 'database' FROM supervision_inspection_committeeminutes_current_audit_users wyhjy_sp LEFT JOIN supervision_inspection_committeeminutes wyhjy_zb ON wyhjy_sp.committeeminutes_id = wyhjy_zb.id LEFT JOIN tb_users_message sq_user ON wyhjy_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wyhjy_sp.user_id = sp_user.id WHERE wyhjy_sp.user_id ={ user_id }
                UNION ALL
				SELECT '行政总值班调班申请' AS types, tbsq_zb.shift_change_reason AS title, CONCAT(date_format( tbsq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( tbsq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN tbsq_zb.state = 'end' THEN '结束' WHEN tbsq_zb.state = 'refuse' THEN '退回' WHEN tbsq_zb.state = 'stop' THEN '终止' WHEN tbsq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/shift_change_detail.html?id=', tbsq_zb.id ) AS url, CASE WHEN tbsq_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '50' AS 'database' FROM supervision_inspection_shiftadjustment_current_audit_users tbsq_sp LEFT JOIN supervision_inspection_shiftadjustment tbsq_zb ON tbsq_sp.shiftadjustment_id = tbsq_zb.id LEFT JOIN tb_users_message sq_user ON tbsq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON tbsq_sp.user_id = sp_user.id WHERE tbsq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '会议请假' AS types, hyqj_zb.reason AS title, CONCAT(date_format( hyqj_zb.create_time, '%Y-%m-%d' ), ' ', time_format( hyqj_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_com.`name` AS department, CASE WHEN hyqj_zb.state = 'end' THEN '结束' WHEN hyqj_zb.state = 'refuse' THEN '退回' WHEN hyqj_zb.state = 'stop' THEN '终止' WHEN hyqj_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/meetingleavedetail.html?id=', hyqj_zb.id ) AS url, CASE WHEN hyqj_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '51' AS 'database' FROM supervision_inspection_meetingroomleave_current_audit_users hyqj_sp LEFT JOIN supervision_inspection_meetingroomleave hyqj_zb ON hyqj_sp.meetingroomleave_id = hyqj_zb.id LEFT JOIN tb_users_message sq_user ON hyqj_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hyqj_sp.user_id = sp_user.id LEFT JOIN administrative_company sq_com ON hyqj_zb.company_id = sq_com.id WHERE hyqj_sp.user_id ={ user_id }
                UNION ALL
                SELECT '数据外导' AS types, sjwd_zb.application_reason AS title, CONCAT(date_format( sjwd_zb.create_time, '%Y-%m-%d' ), ' ', time_format( sjwd_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN sjwd_zb.state = 'end' THEN '结束' WHEN sjwd_zb.state = 'refuse' THEN '退回' WHEN sjwd_zb.state = 'stop' THEN '终止' WHEN sjwd_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/data_export_detail.html?id=', sjwd_zb.id ) AS url, CASE WHEN sjwd_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '51' AS 'database' FROM finance_confidentialdataexport_current_audit_users sjwd_sp LEFT JOIN finance_confidentialdataexport sjwd_zb ON sjwd_sp.confidentialdataexport_id = sjwd_zb.id LEFT JOIN tb_users_message sq_user ON sjwd_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON sjwd_sp.user_id = sp_user.id WHERE sjwd_sp.user_id ={ user_id }
                UNION ALL
                SELECT '公务(外宾)接待事前审批' AS types, jdzq_zb.reception_reason AS title, CONCAT(date_format( jdzq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jdzq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jdzq_zb.state = 'end' THEN '结束' WHEN jdzq_zb.state = 'refuse' THEN '退回' WHEN jdzq_zb.state = 'stop' THEN '终止' WHEN jdzq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/official_business_reception_detail.html?id=', jdzq_zb.id ) AS url, CASE WHEN jdzq_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '51' AS 'database' FROM newflowlogic_beforehandreception_current_audit_users jdzq_sp LEFT JOIN newflowlogic_beforehandreception jdzq_zb ON jdzq_sp.beforehandreception_id = jdzq_zb.id LEFT JOIN tb_users_message sq_user ON jdzq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jdzq_sp.user_id = sp_user.id WHERE jdzq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '公务(外宾)接待清单审批' AS types, jdqd_zb.official_interaction AS title, CONCAT(date_format( jdqd_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jdqd_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jdqd_zb.state = 'end' THEN '结束' WHEN jdqd_zb.state = 'refuse' THEN '退回' WHEN jdqd_zb.state = 'stop' THEN '终止' WHEN jdqd_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/reception_checklist_detail.html?id=', jdqd_zb.id ) AS url, CASE WHEN jdqd_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '51' AS 'database' FROM newflowlogic_receptionchecklist_current_audit_users jdqd_sp LEFT JOIN newflowlogic_receptionchecklist jdqd_zb ON jdqd_sp.receptionchecklist_id = jdqd_zb.id LEFT JOIN tb_users_message sq_user ON jdqd_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jdqd_sp.user_id = sp_user.id WHERE jdqd_sp.user_id ={ user_id }
                UNION ALL
                SELECT '职工出国(境)审批' AS types, zgcg_zb.application_reason AS title, CONCAT(date_format( zgcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( zgcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zgcg_zb.state = 'end' THEN '结束' WHEN zgcg_zb.state = 'refuse' THEN '退回' WHEN zgcg_zb.state = 'stop' THEN '终止' WHEN zgcg_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/employees_abroad_detail.html?id=', zgcg_zb.id ) AS url, CASE WHEN zgcg_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '51' AS 'database' FROM newflowlogic_employeesabroad_current_audit_users zgcg_sp LEFT JOIN newflowlogic_employeesabroad zgcg_zb ON zgcg_sp.employeesabroad_id = zgcg_zb.id LEFT JOIN tb_users_message sq_user ON zgcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zgcg_sp.user_id = sp_user.id WHERE zgcg_sp.user_id ={ user_id }
                UNION ALL
                SELECT '基建维修改造' AS types, jjwx_zb.reason AS title, CONCAT(date_format( jjwx_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jjwx_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jjwx_zb.state = 'end' THEN '结束' WHEN jjwx_zb.state = 'refuse' THEN '退回' WHEN jjwx_zb.state = 'stop' THEN '终止' WHEN jjwx_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/infrastructure-process/InfrastructureRenovationDetail.html?id=', jjwx_zb.id ) AS url, CASE WHEN jjwx_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '55' AS 'database' FROM infrastructure_process_infrastructuremaintenance_current_aud18d7 jjwx_sp LEFT JOIN infrastructure_process_infrastructuremaintenance jjwx_zb ON jjwx_sp.infrastructuremaintenance_id = jjwx_zb.id LEFT JOIN tb_users_message sq_user ON jjwx_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jjwx_sp.user_id = sp_user.id WHERE jjwx_sp.user_id ={ user_id }
                UNION ALL
                SELECT '基建项目专业服务' AS types, jjxm_zb.reason AS title, CONCAT(date_format(jjxm_zb.create_time, '%Y-%m-%d'), ' ', time_format(jjxm_zb.create_time, '%H:%i')) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jjxm_zb.state = 'end' THEN '结束' WHEN jjxm_zb.state = 'refuse' THEN '退回' WHEN jjxm_zb.state = 'stop' THEN '终止' WHEN jjxm_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/infrastructure-process/ProfessionalServicesDetail.html?id=', jjxm_zb.id ) AS url, CASE WHEN jjxm_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '56' AS 'database' FROM infrastructure_process_professionalservices_current_audit_users jjxm_sp LEFT JOIN infrastructure_process_professionalservices jjxm_zb ON jjxm_sp.professionalservices_id = jjxm_zb.id LEFT JOIN tb_users_message sq_user ON jjxm_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jjxm_sp.user_id = sp_user.id WHERE jjxm_sp.user_id ={user_id}
                UNION ALL
                SELECT '体检科支援加班补助' AS types, '体检科支援加班补助' AS title, CONCAT(date_format( jbbz_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jbbz_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jbbz_zb.state = 'end' THEN '结束' WHEN jbbz_zb.state = 'refuse' THEN '退回' WHEN jbbz_zb.state = 'stop' THEN '终止' WHEN jbbz_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/payment-management/OvertimeAllowanceDetail.html?id=', jbbz_zb.id ) AS url, CASE WHEN jbbz_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '57' AS 'database' FROM payment_management_supportsubsidies_current_audit_users jbbz_sp LEFT JOIN payment_management_supportsubsidies jbbz_zb ON jbbz_sp.supportsubsidies_id = jbbz_zb.id LEFT JOIN tb_users_message sq_user ON jbbz_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jbbz_sp.user_id = sp_user.id WHERE jbbz_sp.user_id ={ user_id }
                UNION ALL
                SELECT '工会用印申请' AS types, ghyy_zb.reason AS title, CONCAT(date_format( ghyy_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghyy_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghyy_zb.state = 'end' THEN '结束' WHEN ghyy_zb.state = 'refuse' THEN '退回' WHEN ghyy_zb.state = 'stop' THEN '终止' WHEN ghyy_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/PrintingProcessDetail.html?id=', ghyy_zb.id ) AS url, CASE WHEN ghyy_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '58' AS 'database' FROM union_process_officialseal_current_audit_users ghyy_sp LEFT JOIN union_process_officialseal ghyy_zb ON ghyy_sp.officialseal_id = ghyy_zb.id LEFT JOIN tb_users_message sq_user ON ghyy_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghyy_sp.user_id = sp_user.id WHERE ghyy_sp.user_id ={ user_id }
                UNION ALL
                SELECT '工会经济合同会签' AS types, ghhthq_zb.contract_name AS title, CONCAT(date_format( ghhthq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghhthq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghhthq_zb.state = 'end' THEN '结束' WHEN ghhthq_zb.state = 'refuse' THEN '退回' WHEN ghhthq_zb.state = 'stop' THEN '终止' WHEN ghhthq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/EconomicSigningDetail.html?id=', ghhthq_zb.id ) AS url, CASE WHEN ghhthq_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '59' AS 'database' FROM union_process_economiccountersign_current_audit_users ghhthq_sp LEFT JOIN union_process_economiccountersign ghhthq_zb ON ghhthq_sp.economiccountersign_id = ghhthq_zb.id LEFT JOIN tb_users_message sq_user ON ghhthq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghhthq_sp.user_id = sp_user.id WHERE ghhthq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '工会付款流程' AS types, ghfk_zb.reason AS title, CONCAT(date_format( ghfk_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghfk_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghfk_zb.state = 'end' THEN '结束' WHEN ghfk_zb.state = 'refuse' THEN '退回' WHEN ghfk_zb.state = 'stop' THEN '终止' WHEN ghfk_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/PayFlowDetail.html?id=', ghfk_zb.id ) AS url, CASE WHEN ghfk_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '60' AS 'database' FROM union_process_paymentprocess_current_audit_users ghfk_sp LEFT JOIN union_process_paymentprocess ghfk_zb ON ghfk_sp.paymentprocess_id = ghfk_zb.id LEFT JOIN tb_users_message sq_user ON ghfk_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghfk_sp.user_id = sp_user.id WHERE ghfk_sp.user_id ={ user_id }
                UNION ALL
                SELECT '工会活动审批' AS types, ghsqsp_zb.reason AS title, CONCAT(date_format( ghsqsp_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghsqsp_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghsqsp_zb.state = 'end' THEN '结束' WHEN ghsqsp_zb.state = 'refuse' THEN '退回' WHEN ghsqsp_zb.state = 'stop' THEN '终止' WHEN ghsqsp_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/PreApprovalDetail.html?id=', ghsqsp_zb.id ) AS url, CASE WHEN ghsqsp_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '61' AS 'database' FROM union_process_eventapproval_current_audit_users ghsqsp_sp LEFT JOIN union_process_eventapproval ghsqsp_zb ON ghsqsp_sp.eventapproval_id = ghsqsp_zb.id LEFT JOIN tb_users_message sq_user ON ghsqsp_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghsqsp_sp.user_id = sp_user.id WHERE ghsqsp_sp.user_id ={ user_id }
                UNION ALL
                SELECT '工会物资申购' AS types, ghwzsq_zb.reason AS title, CONCAT(date_format( ghwzsq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghwzsq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghwzsq_zb.state = 'end' THEN '结束' WHEN ghwzsq_zb.state = 'refuse' THEN '退回' WHEN ghwzsq_zb.state = 'stop' THEN '终止' WHEN ghwzsq_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/GoodsSubscribeDetail.html?id=', ghwzsq_zb.id ) AS url, CASE WHEN ghwzsq_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '62' AS 'database' FROM union_process_materialsapproval_current_audit_users ghwzsq_sp LEFT JOIN union_process_materialsapproval ghwzsq_zb ON ghwzsq_sp.materialsapproval_id = ghwzsq_zb.id LEFT JOIN tb_users_message sq_user ON ghwzsq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghwzsq_sp.user_id = sp_user.id WHERE ghwzsq_sp.user_id ={ user_id }
                UNION ALL
                SELECT '门诊排班调整' AS types, mzpb_zb.stop_reason AS title, CONCAT(date_format(mzpb_zb.create_time, '%Y-%m-%d'), ' ', time_format(mzpb_zb.create_time, '%H:%i')) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN mzpb_zb.state = 'end' THEN '结束' WHEN mzpb_zb.state = 'refuse' THEN '退回' WHEN mzpb_zb.state = 'stop' THEN '终止' WHEN mzpb_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/union-process/SchedulingAdjustmentDetail.html?id=', mzpb_zb.id) AS url, CASE WHEN mzpb_zb.state = 'refuse' THEN '修改' ELSE '审批' END AS `text`, '63' AS 'database' FROM union_process_outpatientscheduling_current_audit_users mzpb_sp LEFT JOIN union_process_outpatientscheduling mzpb_zb ON mzpb_sp.outpatientscheduling_id = mzpb_zb.id LEFT JOIN tb_users_message sq_user ON mzpb_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON mzpb_sp.user_id = sp_user.id WHERE mzpb_sp.user_id ={ user_id }
                UNION ALL
				SELECT '维修改造' AS types, wxgz_zb.ApplicationReason AS title, CONCAT(date_format(wxgz_zb.create_time, '%Y-%m-%d' ), ' ', time_format(wxgz_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wxgz_zb.state = 'seven' THEN '结束' WHEN wxgz_zb.state = 'six' THEN '退回' WHEN wxgz_zb.state = 'stop' THEN '终止' WHEN wxgz_zb.state = 'draft' THEN '草稿' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/MaintenanceRenovationDetail.html?id=', wxgz_zb.id ) AS url, CASE WHEN wxgz_zb.state = 'six' THEN '修改' ELSE '审批' END AS `text`, '29' AS 'database' FROM logistics_maintenancerenovation_current_audit_users wxgz_sp LEFT JOIN logistics_maintenancerenovation wxgz_zb ON wxgz_sp.maintenancerenovation_id = wxgz_zb.id LEFT JOIN tb_users_message sq_user ON wxgz_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wxgz_sp.user_id = sp_user.id WHERE wxgz_sp.user_id ={ user_id }
                ) base where 1=1 ORDER BY create_time DESC
                """
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
            data_list = []
            for i in select_data:
                if i[0] in ["用印申请", "院长办公会议题", "党委会议题", "行政例会议题"]:
                    flow_url = "javascript:;"
                    flow_text = f"""<a href="{i[7]}">审批</a> | <a href="javaacript:;" onclick="line_modes('{i[-1]}', {i[7].split("id=")[1]})">搁置</a>"""
                else:
                    flow_url = i[7]
                    flow_text = i[8]
                data_list.append({
                    'types': i[0], 'title': i[1], 'create_time': i[2], 'create_by': i[3], 'department': i[4], "reviewer": i[6],
                    'node': i[5], 'approved': f'<a href="javascript:;" style="color: red;">{i[6]}</a>', 'url': flow_url, 'text': flow_text, "database": i[-1], "id": i[7].split("id=")[1] if len(i[7].split("id=")) >=2 else ''
                })
            return data_list

    def my_done(self, user_id, user_name):
        """我的已办"""
        # UNION ALL
        # SELECT '定义流程' AS Types, b.module as classification, COUNT(a.id) counts FROM system_setup_lowcodebill a left join system_setup_customerform b on a.customer_form_id = b.id left join system_setup_lowcodebill_audit_users_already m on m.lowcodebill_id = a.id WHERE m.user_id={user_id} group by b.module
        # UNION ALL
        # SELECT '资产管理' AS Types, '物资采购' as classification, COUNT(productpurchase_id) counts FROM personal_center_productpurchase_audit_users_already WHERE user_id={user_id}
        # UNION ALL
        # SELECT '资产管理' AS Types, '物资领用' as classification, COUNT(productadopt_id) counts FROM personal_center_productadopt_audit_users_already WHERE user_id={user_id}

        select_sql = f"""
        SELECT * FROM (SELECT '公文管理' AS Types, '上级来文' AS classification, COUNT(A.id) counts FROM administrative_officialdocuments_audit_users_already A LEFT JOIN administrative_officialdocuments B ON A.officialdocuments_id=B.id WHERE B.type NOT IN ('cancel', 'stop') AND A.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '外部来函' AS classification, COUNT(A.id) counts FROM administrative_correspondence_audit_users_already A LEFT JOIN administrative_correspondence B ON A.correspondence_id=B.id WHERE B.type NOT IN ('cancel') AND A.user_id={user_id}
        UNION ALL
        SELECT '公告管理' AS Types, '通知公告' as classification, COUNT(notice_id) counts FROM announcements_notice_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '车辆管理' AS Types, '车辆申请' as classification, COUNT(C.id) counts FROM administrative_vehicleapply_already_users C LEFT JOIN administrative_vehicleapply D ON C.vehicleapply_id=D.id WHERE D.state NOT IN ('cancel', 'stop') AND C.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '党委会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='a' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='b' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '党委专题会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='c' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会专题会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='d' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '行政例会简报' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='e' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医发)' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='f' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '党委公文' as classification, COUNT(E.id) counts FROM administrative_conferencememo_audit_users_already E LEFT JOIN administrative_conferencememo F ON E.conferencememo_id=F.id WHERE F.type='g' AND F.state NOT IN ('cancel', 'stop') AND E.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '京医团总支发文' as classification, COUNT(E.id) counts FROM administrative_conferencememo_audit_users_already E LEFT JOIN administrative_conferencememo F ON E.conferencememo_id=F.id WHERE F.type='i' AND F.state NOT IN ('cancel', 'stop') AND E.user_id={user_id}
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医文)' as classification, COUNT(G.id) counts FROM administrative_conferencememo_audit_users_already G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE H.type='h' AND H.state NOT IN ('cancel', 'stop') AND G.user_id={user_id}
        UNION ALL
        SELECT '会议室管理' AS Types, '会议室申请' as classification, COUNT(I.id) counts FROM personal_center_conferenceroomapplication_audit_users_already I LEFT JOIN personal_center_conferenceroomapplication J ON I.conferenceroomapplication_id=J.id WHERE I.user_id={user_id} AND J.state!='revoke'
        UNION ALL
        SELECT '议题管理' AS Types, '党委会议题' as classification, COUNT(K.id) counts FROM administrative_topics_already_users K LEFT JOIN administrative_topics L ON K.topics_id=L.id WHERE L.type='db' AND L.state NOT IN ('cancel', 'stop') AND K.user_id={user_id}
        UNION ALL
        SELECT '议题管理' AS Types, '院长办公会议题' as classification, COUNT(K.id) counts FROM administrative_topics_already_users K LEFT JOIN administrative_topics L ON K.topics_id=L.id WHERE L.type='yb' AND L.state NOT IN ('cancel', 'stop') AND K.user_id={user_id}
        UNION ALL
        SELECT '议题管理' AS Types, '行政例会议题' as classification, COUNT(K.id) counts FROM administrative_topics_already_users K LEFT JOIN administrative_topics L ON K.topics_id=L.id WHERE L.type='xz' AND L.state NOT IN ('cancel', 'stop') AND K.user_id={user_id}
        UNION ALL
        SELECT '大型活动' AS Types, '大型活动报备' as classification, COUNT(I.id) counts FROM administrative_gatheringapply I LEFT JOIN administrative_gatheringapply_audit_users_already J ON J.gatheringapply_id=I.id WHERE J.user_id={user_id}
        UNION ALL
        SELECT '医德医风' AS Types, '医德医风考评' as classification, COUNT(id) counts FROM medical_ethics_evaluationofmedicalethics_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '用印审批' AS Types, '用印申请' as classification, COUNT(sealapply_id) counts FROM personal_center_sealapply_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '固定资产/维修维保付款' as classification, COUNT(fixedassets_id) counts FROM personal_center_fixedassets_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅申请' as classification, COUNT(travelapply_id) counts FROM finance_travelapply_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '材料付款审批' as classification, COUNT(medicalmaterials_id) counts FROM finance_medicalmaterials_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '付款流程' as classification, COUNT(paymentapproval_id) counts FROM administrative_paymentapproval_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '经济合同会签流程' as classification, COUNT(contractapproval_id) counts FROM administrative_contractapproval_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '一般付款' as classification, COUNT(generalfinance_id) counts FROM finance_generalfinance_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '餐补付款' as classification, COUNT(nutritionalmeals_id) counts FROM finance_nutritionalmeals_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '新增医疗服务项目' as classification, COUNT(newmedicalservices_id) counts FROM finance_newmedicalservices_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '手术分级授权' as classification, COUNT(surgicalgrading_id) counts FROM finance_surgicalgrading_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '合同付款审批' as classification, COUNT(logisticsoffice_id) counts FROM finance_logisticsoffice_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '人事审批' AS Types, '请假申请' as classification, COUNT(leaverequest_id) counts FROM finance_leaverequest_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '临床医师单独执业资格' as classification, COUNT(solopracticeapply_id) counts FROM finance_solopracticeapply_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '经济合同会签' as classification, COUNT(businesscontract_id) counts FROM finance_businesscontract_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅报销' as classification, COUNT(travelreimbursement_id) counts FROM finance_travelreimbursement_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '人事审批' AS Types, '离职申请' as classification, COUNT(dimission_id) counts FROM finance_dimission_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '中层干部外出' as classification, COUNT(outgoingcadresdata_id) counts FROM finance_outgoingcadresdata_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '工会经费' as classification, COUNT(laborunionexpenses_id) counts FROM finance_laborunionexpenses_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '学科经费' as classification, COUNT(subjectfunding_id) counts FROM finance_subjectfunding_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '历史数据管理' AS Types, '科研经费' as classification, COUNT(researchfunding_id) counts FROM finance_researchfunding_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '用印审批' AS Types, '印章刻制' as classification, COUNT(sealmaking_id) counts FROM finance_sealmaking_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '用印审批' AS Types, '快速用印授权' as classification, COUNT(quickauthorization_id) counts FROM finance_quickauthorization_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '图书/报刊/杂志征订' as classification, COUNT(booksubscription_id) counts FROM finance_booksubscription_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '党建经费' as classification, COUNT(partybuilding_id) counts FROM finance_partybuilding_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '项目审计送审申请' as classification, COUNT(objectaudit_id) counts FROM finance_objectaudit_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '招标结果汇报会签' as classification, COUNT(tenderingsigning_id) counts FROM logistics_tenderingsigning_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '服务采购' as classification, COUNT(purchasingrequisition_id) counts FROM logistics_purchasingrequisition_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '货物采购' as classification, COUNT(goodsprocure_id) counts FROM logistics_goodsprocure_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '维修改造' as classification, COUNT(maintenancerenovation_id) counts FROM logistics_maintenancerenovation_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '网络信息' AS Types, '计算机及相关设备购置' as classification, COUNT(computerdevice_id) counts FROM logistics_computerdevice_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '项目管理' AS Types, '招标采购项目' as classification, COUNT(id) counts FROM logistics_biddingprocurementproject_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '会议室管理' AS Types, '短信审批' as classification, COUNT(id) counts FROM supervision_inspection_shortmessageapproval_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '流程节点修改' as classification, COUNT(id) counts FROM supervision_inspection_flowmodify_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '问责申请' as classification, COUNT(id) counts FROM supervision_inspection_initiateaccountability_audit_users_al710e WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '委员会议题' as classification, COUNT(id) counts FROM supervision_inspection_committeetopics_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '督办督查' AS Types, '委员会纪要' as classification, COUNT(id) counts FROM supervision_inspection_committeeminutes_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '人事审批' AS Types, '行政总值班调班申请' as classification, COUNT(id) counts FROM supervision_inspection_shiftadjustment_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '会议室管理' AS Types, '会议请假' as classification, COUNT(id) counts FROM supervision_inspection_meetingroomleave_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '网络信息' AS Types, '数据外导' as classification, COUNT(id) counts FROM finance_confidentialdataexport_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '公务(外宾)接待事前审批' as classification, COUNT(id) counts FROM newflowlogic_beforehandreception_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '公务(外宾)接待清单审批' as classification, COUNT(id) counts FROM newflowlogic_receptionchecklist_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '差旅审批' AS Types, '职工出国(境)审批' as classification, COUNT(id) counts FROM newflowlogic_employeesabroad_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '基建维修改造' as classification, COUNT(id) counts FROM infrastructure_process_infrastructuremaintenance_audit_users98e6 WHERE user_id={user_id}
        UNION ALL
        SELECT '后勤管理' AS Types, '基建项目专业服务' as classification, COUNT(id) counts FROM infrastructure_process_professionalservices_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '付款审批' AS Types, '体检科支援加班补助' as classification, COUNT(id) counts FROM payment_management_supportsubsidies_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会用印申请' as classification, COUNT(id) counts FROM union_process_officialseal_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会经济合同会签' as classification, COUNT(id) counts FROM union_process_economiccountersign_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会付款流程' as classification, COUNT(id) counts FROM union_process_paymentprocess_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会活动审批' as classification, COUNT(id) counts FROM union_process_eventapproval_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '工会服务' AS Types, '工会物资申购' as classification, COUNT(id) counts FROM union_process_materialsapproval_audit_users_already WHERE user_id={user_id}
        UNION ALL
        SELECT '临床管理' AS Types, '门诊排班调整' as classification, COUNT(id) counts FROM union_process_outpatientscheduling_audit_users_already WHERE user_id={user_id}
        ) Z ORDER BY counts DESC
        """
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
        select_data = list(select_data)
        modul_sql = "SELECT id, module AS Types, `name` AS classification FROM system_setup_customerform"
        with connection.cursor() as cursor:
            cursor.execute(modul_sql)
            modul_data = cursor.fetchall()
            for modul in modul_data:
                bill_sql = f"SELECT '{modul[1]}' AS Types, '{modul[2]}' as classification, COUNT(A.id) counts FROM system_setup_lowcodebill_audit_users_already A LEFT JOIN system_setup_lowcodebill B ON A.lowcodebill_id=B.id WHERE user_id={user_id} AND B.customer_form_id={modul[0]}"
                with connection.cursor() as cursor:
                    cursor.execute(bill_sql)
                    bill_data = cursor.fetchall()
                    select_data.append(bill_data[0])
        return select_data

    def my_apply(self, user_id, user_name, department):
        """我的申请"""
        # UNION ALL
        # SELECT '定义流程' AS Types, b.module as classification, COUNT(a.id) counts FROM system_setup_lowcodebill a left join system_setup_customerform b on a.customer_form_id = b.id WHERE a.apply_user_id={user_id} group by b.module
        # UNION ALL
        # SELECT '资产管理' AS Types, '物资领用' as classification, COUNT(id) counts FROM personal_center_productadopt WHERE apply_user_id={user_id}
        # UNION ALL
        # SELECT '资产管理' AS Types, '物资采购' as classification, COUNT(id) counts FROM personal_center_productpurchase WHERE apply_user_id={user_id}
        select_sql = f"""
                SELECT * FROM (SELECT '公文管理' AS Types, '党委会议纪要' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='a' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '院长办公会会议纪要' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='b' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '党委专题会议纪要' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='c' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '院长办公会专题会议纪要' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='d' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '行政例会简报' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='e' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '行政公文(京医发)' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='f' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '党委公文' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='g' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '京医团总支发文' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='i' AND apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '行政公文(京医文)' as classification, COUNT(id) counts FROM administrative_conferencememo WHERE type='h' AND apply_user_id={user_id}
                UNION ALL
                SELECT '议题管理' AS Types, '党委会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE type='db' AND employee_id={user_id}
                UNION ALL
                SELECT '议题管理' AS Types, '院长办公会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE type='yb' AND employee_id={user_id}
                UNION ALL
                SELECT '议题管理' AS Types, '行政例会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE type='xz' AND employee_id={user_id}
                UNION ALL
                SELECT '会议室管理' AS Types, '会议室申请' as classification, COUNT(id) counts FROM personal_center_conferenceroomapplication WHERE `names`='{user_name}' AND department='{department}'
                UNION ALL
                SELECT '车辆管理' AS Types, '车辆申请' as classification, COUNT(id) counts FROM administrative_vehicleapply WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '公告管理' AS Types, '通知公告' AS classification, COUNT(id) counts FROM announcements_notice WHERE create_people_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '上级来文' AS classification, COUNT(id) counts FROM administrative_officialdocuments WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '公文管理' AS Types, '外部来函' AS classification, COUNT(id) counts FROM administrative_correspondence WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '大型活动' AS Types, '大型活动报备' AS classification, COUNT(id) counts FROM administrative_gatheringapply WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '医德医风' AS Types, '医德医风考评' as classification, COUNT(id) counts FROM medical_ethics_evaluationofmedicalethics WHERE apply_user_id={user_id} AND state IN ('one', 'two', 'three', 'four', 'five')
                UNION ALL
                SELECT '用印审批' AS Types, '用印申请' as classification, COUNT(id) counts FROM personal_center_sealapply WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '固定资产/维修维保付款' as classification, COUNT(id) counts FROM personal_center_fixedassets WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '材料付款' as classification, COUNT(id) counts FROM finance_medicalmaterials WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '一般付款' as classification, COUNT(id) counts FROM finance_generalfinance WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '餐补付款' as classification, COUNT(id) counts FROM finance_nutritionalmeals WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '付款审批' AS Types, '付款流程' as classification, COUNT(id) counts FROM administrative_paymentapproval WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '项目管理' AS Types, '经济合同会签流程' as classification, COUNT(id) counts FROM administrative_contractapproval WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '临床管理' AS Types, '新增医疗服务项目' as classification, COUNT(id) counts FROM finance_newmedicalservices WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '合同付款' as classification, COUNT(id) counts FROM finance_logisticsoffice WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '人事审批' AS Types, '请假申请' as classification, COUNT(id) counts FROM finance_leaverequest WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '临床管理' AS Types, '手术分级授权' as classification, COUNT(id) counts FROM finance_surgicalgrading WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '临床管理' AS Types, '临床医师单独执业资格' as classification, COUNT(id) counts FROM finance_solopracticeapply WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '经济合同会签' as classification, COUNT(id) counts FROM finance_businesscontract WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '差旅审批' AS Types, '差旅报销' as classification, COUNT(id) counts FROM finance_travelreimbursement WHERE applicat_id={user_id}
                UNION ALL
                SELECT '差旅审批' AS Types, '差旅申请' as classification, COUNT(id) counts FROM finance_travelapply WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '人事审批' AS Types, '离职申请' as classification, COUNT(id) counts FROM finance_dimission WHERE user_id={user_id}
                UNION ALL
                SELECT '差旅审批' AS Types, '中层干部外出' as classification, COUNT(id) counts FROM finance_outgoingcadresdata WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '工会经费' as classification, COUNT(id) counts FROM finance_laborunionexpenses WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '用印审批' AS Types, '印章刻制' as classification, COUNT(id) counts FROM finance_sealmaking WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '学科经费' as classification, COUNT(id) counts FROM finance_subjectfunding WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '历史数据管理' AS Types, '科研经费' as classification, COUNT(id) counts FROM finance_researchfunding WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '用印审批' AS Types, '快速用印授权' as classification, COUNT(id) counts FROM finance_quickauthorization WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '图书/报刊/杂志征订' as classification, COUNT(id) counts FROM finance_booksubscription WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '付款审批' AS Types, '党建经费' as classification, COUNT(id) counts FROM finance_partybuilding WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '项目管理' AS Types, '项目审计送审申请' as classification, COUNT(id) counts FROM finance_objectaudit WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '服务采购' as classification, COUNT(id) counts FROM logistics_purchasingrequisition WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '货物采购' as classification, COUNT(id) counts FROM logistics_goodsprocure WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '维修改造' as classification, COUNT(id) counts FROM logistics_maintenancerenovation WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '网络信息' AS Types, '计算机及相关设备购置' as classification, COUNT(id) counts FROM logistics_computerdevice WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '项目管理' AS Types, '招标采购项目' as classification, COUNT(id) counts FROM logistics_biddingprocurementproject WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '项目管理' AS Types, '招标结果汇报会签' as classification, COUNT(id) counts FROM logistics_tenderingsigning WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '会议室管理' AS Types, '短信审批' as classification, COUNT(id) counts FROM supervision_inspection_shortmessageapproval WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '督办督查' AS Types, '流程节点修改' as classification, COUNT(id) counts FROM supervision_inspection_flowmodify WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '督办督查' AS Types, '问责申请' as classification, COUNT(id) counts FROM supervision_inspection_initiateaccountability WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '督办督查' AS Types, '委员会议题' as classification, COUNT(id) counts FROM supervision_inspection_committeetopics WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '督办督查' AS Types, '委员会纪要' as classification, COUNT(id) counts FROM supervision_inspection_committeeminutes WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '人事审批' AS Types, '行政总值班调班申请' as classification, COUNT(id) counts FROM supervision_inspection_shiftadjustment WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '会议室管理' AS Types, '会议请假' as classification, COUNT(id) counts FROM supervision_inspection_meetingroomleave WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '网络信息' AS Types, '数据外导' as classification, COUNT(id) counts FROM finance_confidentialdataexport WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '付款审批' AS Types, '公务(外宾)接待事前审批' as classification, COUNT(id) counts FROM newflowlogic_beforehandreception WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '付款审批' AS Types, '公务(外宾)接待清单审批' as classification, COUNT(id) counts FROM newflowlogic_receptionchecklist WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '差旅审批' AS Types, '职工出国(境)审批' as classification, COUNT(id) counts FROM newflowlogic_employeesabroad WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '基建维修改造' as classification, COUNT(id) counts FROM infrastructure_process_infrastructuremaintenance WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '后勤管理' AS Types, '基建项目专业服务' as classification, COUNT(id) counts FROM infrastructure_process_professionalservices WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '付款审批' AS Types, '体检科支援加班补助' as classification, COUNT(id) counts FROM payment_management_supportsubsidies WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '工会服务' AS Types, '工会用印申请' as classification, COUNT(id) counts FROM union_process_officialseal WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '工会服务' AS Types, '工会经济合同会签' as classification, COUNT(id) counts FROM union_process_economiccountersign WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '工会服务' AS Types, '工会付款流程' as classification, COUNT(id) counts FROM union_process_paymentprocess WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '工会服务' AS Types, '工会活动审批' as classification, COUNT(id) counts FROM union_process_eventapproval WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '工会服务' AS Types, '工会物资申购' as classification, COUNT(id) counts FROM union_process_materialsapproval WHERE apply_user_id={user_id}
                UNION ALL
                SELECT '临床管理' AS Types, '门诊排班调整' as classification, COUNT(id) counts FROM union_process_outpatientscheduling WHERE apply_user_id={user_id}
                ) Z ORDER BY counts DESC
                """
        with connection.cursor() as cursor:
            # print(select_sql)
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
        select_data = list(select_data)
        modul_sql = "SELECT id, module AS Types, `name` AS classification FROM system_setup_customerform"
        with connection.cursor() as cursor:
            cursor.execute(modul_sql)
            modul_data = cursor.fetchall()
            for modul in modul_data:
                bill_sql = f"SELECT '{modul[1]}' AS Types, '{modul[2]}' as classification, COUNT(id) counts FROM system_setup_lowcodebill WHERE apply_user_id={user_id} AND customer_form_id={modul[0]}"
                with connection.cursor() as cursor:
                    cursor.execute(bill_sql)
                    bill_data = cursor.fetchall()
                    select_data.append(bill_data[0])
        return select_data

    def apply_post(self, user_id, user_name):
        """我的申请 POST 请求数据"""
        # UNION ALL
        # SELECT '物资领用' AS types, wzcg_zb.number as title, CONCAT(date_format(wzcg_zb.create_time, '%Y-%m-%d'), ' ', time_format(wzcg_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when wzcg_zb.state = 'two' then '结束' when wzcg_zb.state = 'four' then '退回' when wzcg_zb.state = 'cancel' then '作废' when wzcg_zb.state = 'stop' then '终止' when wzcg_zb.state = 'recall' then '撤回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('product_adopt_detail_view?id=', wzcg_zb.id) as url, case when wzcg_zb.state = 'four' then '修改' else '审批' END as `text` FROM personal_center_productpurchase_current_audit_users wzcg_sp LEFT JOIN personal_center_productadopt wzcg_zb ON wzcg_sp.productpurchase_id=wzcg_zb.id LEFT JOIN tb_users_message sq_user on wzcg_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on wzcg_sp.user_id=sp_user.id WHERE wzcg_sp.user_id={user_id}
        # UNION ALL
        # SELECT '物资采购' as types, wzly_zb.number as title, CONCAT(date_format(wzly_zb.create_time, '%Y-%m-%d'), ' ', time_format(wzly_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when wzly_zb.state = 'two' then '结束' when wzly_zb.state = 'four' then '退回' when wzly_zb.state = 'cancel' then '作废' when wzly_zb.state = 'stop' then '终止' when wzly_zb.state = 'recall' then '撤回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('product_shenpi_view?id=', wzly_zb.id) as url, case when wzly_zb.state = 'four' then '修改' else '审批' END as `text` FROM personal_center_productpurchase_current_audit_users wzly_sp LEFT JOIN personal_center_productpurchase wzly_zb ON wzly_sp.productpurchase_id=wzly_zb.id LEFT JOIN tb_users_message sq_user on wzly_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on wzly_sp.user_id=sp_user.id WHERE wzly_sp.user_id={user_id}
        select_sql = f"""
                SELECT * FROM (
                SELECT '上级来文' as types, a.title as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.type = 'f' then '退回' when a.type = 'g' then '待分发' else '审核中	' END as node, GROUP_CONCAT(DISTINCT au.real_name SEPARATOR ',') as approved, case when a.type IN ('g', 'f') then CONCAT('examinationDetail.html?approve=1&id=', a.id) ELSE  CONCAT('examinationDetail.html?id=', a.id) END as url, case when a.type = 'g' then '分发' when a.type = 'f' then '修改' else '查看' END as `text` FROM administrative_officialdocuments a	INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id left join administrative_officialdocuments_current_audit_users m on m.officialdocuments_id = a.id LEFT JOIN tb_users_message au on m.user_id = au.id where a.apply_user_id = {user_id} AND a.type IN ('a', 'b', 'c', 'f', 'g', 'h') GROUP BY types, title, create_time, create_by, department, node, url, `text`
                UNION ALL				
                SELECT '外部来函' AS types, a.title AS title, CONCAT(date_format( a.create_time, '%Y-%m-%d' ), ' ', time_format( a.create_time, '%H:%i' )) AS create_time, u.real_name AS create_by, c.`name` AS department, CASE WHEN a.type = 'six' THEN '退回' WHEN a.type = 'seven' THEN '待分发' WHEN a.type = 'four' THEN '传阅中' ELSE '审核中	' END AS node, GROUP_CONCAT( DISTINCT au.real_name SEPARATOR ',' ) AS approved, CASE WHEN a.type IN ( 'six', 'seven' ) THEN CONCAT( 'ExternalCorrespondenceDetail.html?approve=1&id=', a.id ) ELSE CONCAT( 'ExternalCorrespondenceDetail.html?id=', a.id ) END AS url, CASE WHEN a.type = 'seven' THEN '分发' WHEN a.type = 'six' THEN '修改' ELSE '查看' END AS `text` FROM administrative_correspondence a INNER JOIN tb_users_message u ON a.apply_user_id = u.id INNER JOIN administrative_company c ON u.company_id = c.id LEFT JOIN administrative_correspondence_current_audit_users m ON m.correspondence_id = a.id LEFT JOIN tb_users_message au ON m.user_id = au.id WHERE a.apply_user_id = { user_id } AND a.type IN ( 'one', 'two', 'three', 'six', 'seven', 'eight') GROUP BY types, title, create_time, create_by, department, node, url, `text` 
	            UNION ALL
                SELECT (case when a.type = 'a' then '党委会议纪要' when a.type = 'b' then '院长办公会会议纪要' when a.type = 'c' then '党委专题会议纪要' when a.type = 'd' then '院长办公会专题会议纪要' when a.type = 'e' then '行政例会简报' when a.type = 'f' then '京医发' when a.type = 'g' then '党委公文' when a.type = 'h' then '京医文' when a.type = 'i' then '京医团总支发文' END) as types, a.conference_memo_text as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'six' then '退回' when a.state = 'eight' then '待分发' else '审核中' END as node, GROUP_CONCAT(DISTINCT au.real_name SEPARATOR ',') as approved, case when a.state = 'six' then CONCAT('refer_back.html?id=', a.id) else CONCAT('document_detail.html?id=', a.id) END as url, case when a.state = 'six' then '修改' when a.state = 'eight' then '分发' else '查看' END as `text` FROM administrative_conferencememo a INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id left join administrative_conferencememo_current_audit_users m on m.conferencememo_id = a.id LEFT JOIN tb_users_message au on m.user_id = au.id where a.apply_user_id = {user_id} AND a.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'eight', 'nine', 'ten') GROUP BY types, title, create_time, create_by, department, node, url, `text`                
                UNION ALL
                SELECT'通知公告' AS types, tzgg_zb.`name` AS title, CONCAT(date_format( tzgg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( tzgg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN tzgg_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CASE WHEN tzgg_zb.state = 'eight' THEN CONCAT( '/announcements/notice_change.html?id=', tzgg_zb.id ) ELSE CONCAT('/announcements/notice_approve.html?id=', tzgg_zb.id) END AS url, CASE WHEN tzgg_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM announcements_notice tzgg_zb LEFT JOIN announcements_notice_current_audit_users tzgg_sp ON tzgg_sp.notice_id = tzgg_zb.id LEFT JOIN tb_users_message sq_user ON tzgg_zb.create_people_id = sq_user.id LEFT JOIN tb_users_message sp_user ON tzgg_sp.user_id = sp_user.id WHERE tzgg_zb.create_people_id ={ user_id } AND tzgg_zb.state IN ( 'one', 'two', 'eight')
                UNION ALL
                SELECT '车辆管理' AS types, a.`subject` as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'refuse' then '退回'  else '审核中' END as node, au.real_name as approved, CONCAT('Vehicle_apply_detail.html?id=', a.id) as url, case when a.state = 'refuse' then '修改' else '查看' END as `text` from administrative_vehicleapply a INNER JOIN tb_users_message u on a.apply_user_id = u.id INNER JOIN administrative_company c on u.company_id = c.id LEFT JOIN tb_users_message au on au.id = a.current_audit_user_id where a.apply_user_id = {user_id} AND a.state IN ('draft', 'fg', 'ybzr', 'refuse')	
                UNION ALL
                SELECT (case when a.type = 'db' then '党委会议题' when a.type = 'yb' then '院长办公会议题' when a.type = 'xz' then '行政例会议题' END) as types, a.topics_name as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, u.real_name as create_by, c.`name` as department, case when a.state = 'refuse' then '退回' else '审核中' END as node, a.current_audit_user as approved, case when a.state = 'refuse' then CONCAT('Issue_modify.html?id=', a.id) else CONCAT('SubjectDetailst.html?views=1&id=', a.id) END as url, case when a.state = 'refuse'  then '修改' else '查看' END as `text` FROM administrative_topics a INNER JOIN tb_users_message u on a.employee_id = u.id INNER JOIN administrative_company c on u.company_id = c.id where a.employee_id ={user_id} AND a.state IN ('cg', 'draft', 'confirm', 'audit', 'yd_leader', 'refuse', 'sj')	
                UNION ALL
                SELECT '会议室申请' as types, a.meeting_root as title, CONCAT(date_format(a.create_time, '%Y-%m-%d'), ' ', time_format(a.create_time, '%H:%i')) as create_time, a.names as create_by, a.department as department, '审核中' as node, u.real_name as approved, CONCAT('conference_room_detail?id=', a.id) as url, '查看' as `text` FROM personal_center_conferenceroomapplication a left join tb_users_message u on a.audit_people_id = u.id where a.`names` = '{user_name}' AND a.state='unaudit'
                UNION ALL
                SELECT '大型活动报备' as types, hdbbzb.gathering_note as title, CONCAT(date_format(hdbbzb.create_time, '%Y-%m-%d'), ' ', time_format(hdbbzb.create_time, '%H:%i')) as create_time, sp_user.real_name as create_by, sp_user.department as department, case when hdbbzb.state = 'three' then '拒绝' else '审核中' END as node, user_table.real_name as approved, CONCAT('/administrative/gathering_apply_detail_view?id=', hdbbzb.id) as url, case when hdbbzb.state = 'three' then '修改' else '查看' END as `text` FROM administrative_gatheringapply hdbbzb LEFT JOIN administrative_gatheringapply_current_audit_users hdbbpb ON hdbbpb.gatheringapply_id=hdbbzb.id LEFT JOIN tb_users_message user_table on hdbbpb.user_id=user_table.id LEFT JOIN tb_users_message sp_user on hdbbzb.apply_user_id=sp_user.id WHERE hdbbzb.apply_user_id={user_id} AND hdbbzb.state IN ('three', 'one', 'two')
                UNION ALL
                SELECT '临床医师单独执业资格' as types, lcys_zb.doctor_qualified_number as title, CONCAT(date_format(lcys_zb.create_time, '%Y-%m-%d'), ' ', time_format(lcys_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when lcys_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/solo_practice_apply_detail_view?id=', lcys_zb.id) as url, case when lcys_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_solopracticeapply lcys_zb LEFT JOIN finance_solopracticeapply_current_audit_users lcys_sp ON lcys_sp.solopracticeapply_id=lcys_zb.id LEFT JOIN tb_users_message sq_user on lcys_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on lcys_sp.user_id=sp_user.id WHERE lcys_zb.apply_user_id={user_id} AND lcys_zb.state IN ('one', 'two', 'eight')
                UNION ALL
                SELECT '手术分级授权' as types, shfq_zb.reason as title, CONCAT(date_format(shfq_zb.create_time, '%Y-%m-%d'), ' ', time_format(shfq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when shfq_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/surgical_grading_detail_view?id=', shfq_zb.id) as url, case when shfq_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_surgicalgrading shfq_zb LEFT JOIN finance_surgicalgrading_current_audit_users shfq_sp ON shfq_sp.surgicalgrading_id=shfq_zb.id LEFT JOIN tb_users_message sq_user on shfq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on shfq_sp.user_id=sp_user.id WHERE shfq_zb.apply_user_id={user_id} AND shfq_zb.state IN ('one', 'two', 'three', 'eight')
                UNION ALL
                SELECT '新增医疗服务项目' as types, xzyl_zb.title as title, CONCAT(date_format(xzyl_zb.create_time, '%Y-%m-%d'), ' ', time_format(xzyl_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when xzyl_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/new_medical_services_detail_view?id=', xzyl_zb.id) as url, case when xzyl_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_newmedicalservices xzyl_zb LEFT JOIN finance_newmedicalservices_current_audit_users xzyl_sp ON xzyl_sp.newmedicalservices_id=xzyl_zb.id LEFT JOIN tb_users_message sq_user on xzyl_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on xzyl_sp.user_id=sp_user.id WHERE xzyl_zb.apply_user_id={user_id} AND xzyl_zb.state IN ('one', 'two', 'three', 'eight', 'four', 'five')
                UNION ALL
                SELECT '离职申请' as types, lzsq_zb.dimission_note as title, CONCAT(date_format(lzsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(lzsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when lzsq_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/dimission_detail_view?id=', lzsq_zb.id) as url, case when lzsq_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_dimission lzsq_zb LEFT JOIN finance_dimission_current_audit_users lzsq_sp ON lzsq_sp.dimission_id=lzsq_zb.id LEFT JOIN tb_users_message sq_user on lzsq_zb.user_id=sq_user.id LEFT JOIN tb_users_message sp_user on lzsq_sp.user_id=sp_user.id WHERE lzsq_zb.user_id={user_id} AND lzsq_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'eight')
                UNION ALL
                SELECT '请假申请' as types, qjsq_zb.reason as title, CONCAT(date_format(qjsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(qjsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when qjsq_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/leave_request_detail_view?id=', qjsq_zb.id) as url, case when qjsq_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_leaverequest qjsq_zb LEFT JOIN finance_leaverequest_current_audit_users qjsq_sp ON qjsq_sp.leaverequest_id=qjsq_zb.id LEFT JOIN tb_users_message sq_user on qjsq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on qjsq_sp.user_id=sp_user.id WHERE qjsq_zb.apply_user_id={user_id} AND qjsq_zb.state IN ('one', 'two', 'three', 'eight', 'four')
                UNION ALL
                SELECT '一般付款' as types, cgfk_zb.title as title, CONCAT(date_format(cgfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(cgfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when cgfk_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/general_finance_detail_view?id=', cgfk_zb.id) as url, case when cgfk_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_generalfinance cgfk_zb LEFT JOIN finance_generalfinance_current_audit_users cgfk_sp ON cgfk_sp.generalfinance_id=cgfk_zb.id LEFT JOIN tb_users_message sq_user on cgfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on cgfk_sp.user_id=sp_user.id WHERE cgfk_zb.apply_user_id={user_id} AND cgfk_zb.state IN ('one', 'two', 'three', 'eight', 'four', 'five')
                UNION ALL
                SELECT '餐补付款' as types, yykfk_zb.title as title, CONCAT(date_format(yykfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(yykfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yykfk_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/nutritional_meals_detail_view?id=', yykfk_zb.id) as url, case when yykfk_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_nutritionalmeals yykfk_zb LEFT JOIN finance_nutritionalmeals_current_audit_users yykfk_sp ON yykfk_sp.nutritionalmeals_id=yykfk_zb.id LEFT JOIN tb_users_message sq_user on yykfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yykfk_sp.user_id=sp_user.id WHERE yykfk_zb.apply_user_id={user_id} AND yykfk_zb.state IN ('one', 'two', 'three', 'eight', 'four', 'five', 'six')
                UNION ALL
                SELECT '付款流程' AS types, fklc_zb.title AS title, CONCAT(date_format( fklc_zb.create_time, '%Y-%m-%d' ), ' ', time_format( fklc_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_com.name AS department, CASE WHEN fklc_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/payment_process_detail.html?id=', fklc_zb.id ) AS url, CASE WHEN fklc_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM administrative_paymentapproval fklc_zb LEFT JOIN administrative_paymentapproval_current_audit_users fklc_sp ON fklc_sp.paymentapproval_id = fklc_zb.id LEFT JOIN tb_users_message sq_user ON fklc_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON fklc_sp.user_id = sp_user.id LEFT JOIN administrative_company sq_com ON fklc_zb.company_id=sq_com.id WHERE fklc_zb.apply_user_id ={ user_id } AND fklc_zb.state IN ( 'one', 'two', 'three', 'eight', 'four', 'five', 'six', "zero" )
                UNION ALL
                SELECT '经济合同会签流程' AS types, hthq_zb.title AS title, CONCAT(date_format( hthq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( hthq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN hthq_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/ContractDetail.html?id=', hthq_zb.id ) AS url, CASE WHEN hthq_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM administrative_contractapproval hthq_zb LEFT JOIN administrative_contractapproval_current_audit_users hthq_sp ON hthq_sp.contractapproval_id = hthq_zb.id LEFT JOIN tb_users_message sq_user ON hthq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hthq_sp.user_id = sp_user.id WHERE hthq_zb.apply_user_id ={ user_id } AND hthq_zb.state IN ( 'one', 'two', 'three', 'eight', 'four', 'five', 'six' )
                UNION ALL
                SELECT '合同付款' as types, htfk_zb.pay_reason as title, CONCAT(date_format(htfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(htfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when htfk_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/logistics_office_apply_detail_view?id=', htfk_zb.id) as url, case when htfk_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_logisticsoffice htfk_zb LEFT JOIN finance_logisticsoffice_current_audit_users htfk_sp ON htfk_sp.logisticsoffice_id=htfk_zb.id LEFT JOIN tb_users_message sq_user on htfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on htfk_sp.user_id=sp_user.id WHERE htfk_zb.apply_user_id={user_id} AND htfk_zb.state IN ('one', 'two', 'three', 'eight', 'four', 'five' , 'six')
                UNION ALL
                SELECT '材料付款' as types, clfk_zb.title as title, CONCAT(date_format(clfk_zb.create_time, '%Y-%m-%d'), ' ', time_format(clfk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clfk_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/medical_materials_detail_view?id=', clfk_zb.id) as url, case when clfk_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_medicalmaterials clfk_zb LEFT JOIN finance_medicalmaterials_current_audit_users clfk_sp ON clfk_sp.medicalmaterials_id=clfk_zb.id LEFT JOIN tb_users_message sq_user on clfk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on clfk_sp.user_id=sp_user.id WHERE clfk_zb.apply_user_id={user_id} AND clfk_zb.state IN ('one', 'two', 'three', 'eight', 'four', 'five', 'six')
                UNION ALL
                SELECT '经济合同会签' as types, jjht_zb.contract_name as title, CONCAT(date_format(jjht_zb.create_time, '%Y-%m-%d'), ' ', time_format(jjht_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when jjht_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/business_contract_detail_view?id=', jjht_zb.id) as url, case when jjht_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_businesscontract jjht_zb LEFT JOIN finance_businesscontract_current_audit_users jjht_sp ON jjht_sp.businesscontract_id=jjht_zb.id LEFT JOIN tb_users_message sq_user on jjht_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on jjht_sp.user_id=sp_user.id WHERE jjht_zb.apply_user_id={user_id} AND jjht_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'eight', 'nine', 'ten', 'eleven')
                UNION ALL
                SELECT '差旅报销' as types, clbx_zb.business_matter as title, CONCAT(date_format(clbx_zb.create_time, '%Y-%m-%d'), ' ', time_format(clbx_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clbx_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/travel_approval.html?id=', clbx_zb.id) as url, case when clbx_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_travelreimbursement clbx_zb LEFT JOIN finance_travelreimbursement_current_audit_users clbx_sp ON clbx_sp.travelreimbursement_id=clbx_zb.id LEFT JOIN tb_users_message sq_user on clbx_zb.applicat_id=sq_user.id LEFT JOIN tb_users_message sp_user on clbx_sp.user_id=sp_user.id WHERE clbx_zb.applicat_id={user_id} AND clbx_zb.state IN ('one', 'two', 'three', 'four', 'five' , 'six', 'eight')
                UNION ALL
                SELECT '差旅申请' as types, clsq_zb.subject as title, CONCAT(date_format(clsq_zb.create_time, '%Y-%m-%d'), ' ', time_format(clsq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when clsq_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/travel_apply_detail_view?id=', clsq_zb.id) as url, case when clsq_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_travelapply clsq_zb LEFT JOIN finance_travelapply_current_audit_users clsq_sp ON clsq_sp.travelapply_id=clsq_zb.id LEFT JOIN tb_users_message sq_user on clsq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on clsq_sp.user_id=sp_user.id WHERE clsq_zb.apply_user_id={user_id} AND clsq_zb.state IN ('one', 'two', 'three', 'four', 'eight')
                UNION ALL
                SELECT '固定资产/维修维保付款' as types,fksq_zb.title as title, CONCAT(date_format(fksq_zb.create_time, '%Y-%m-%d'), ' ', time_format(fksq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when fksq_zb.state = 'seven' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/fixed_assets_apply_detail_view?id=', fksq_zb.id) as url, case when fksq_zb.state = 'seven' then '修改' else '查看' END as `text` FROM personal_center_fixedassets fksq_zb LEFT JOIN personal_center_fixedassets_current_audit_users fksq_sp ON fksq_sp.fixedassets_id =fksq_zb.id LEFT JOIN tb_users_message sq_user on fksq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on fksq_sp.user_id=sp_user.id WHERE fksq_zb.apply_user_id={user_id} AND fksq_zb.state IN ('one', 'two', 'three', 'four', 'five' , 'seven')
                UNION ALL
                SELECT case when yyspzb.is_fast = 1 then '快捷用印申请' else '用印申请' END as types, yyspzb.matter_type_text as title, CONCAT(date_format(yyspzb.create_time, '%Y-%m-%d'), ' ', time_format(yyspzb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yyspzb.state = 'six' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('seal_apply_detail_view?id=', yyspzb.id) as url, case when yyspzb.state = 'six' then '修改' else '查看' END as `text` FROM personal_center_sealapply yyspzb LEFT JOIN personal_center_sealapply_current_audit_users yysqsp ON yysqsp.sealapply_id=yyspzb.id LEFT JOIN tb_users_message sq_user on yyspzb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yysqsp.user_id=sp_user.id WHERE yyspzb.apply_user_id={user_id} AND yyspzb.state NOT IN ('draft', 'five', 'cancel', 'stop', 'recall')                
                UNION ALL
                SELECT '医德医风考评' AS types, ydyfzb.title AS title, CONCAT(date_format( ydyfzb.create_time, '%Y-%m-%d' ), ' ', time_format( ydyfzb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, CASE WHEN ydyfzb.apply_company_id = "1001" THEN '医德医风评选一组' WHEN ydyfzb.apply_company_id = "1002" THEN '医德医风评选二组' WHEN ydyfzb.apply_company_id = "1003" THEN '医德医风评选三组' WHEN ydyfzb.apply_company_id = "1004" THEN '医德医风评选四组' ELSE my_com.`name` END AS department, CASE WHEN ydyfzb.state = 'three' THEN '已提交' WHEN ydyfzb.state = 'four' THEN '评审小组审核中' WHEN ydyfzb.state = 'five' THEN '已完结' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/medical-ethics/medical_ethics_detail_view?id=', ydyfzb.id ) AS url, '查看' AS `text` FROM medical_ethics_evaluationofmedicalethics ydyfzb LEFT JOIN medical_ethics_evaluationofmedicalethics_current_audit_users ydyfpb ON ydyfpb.evaluationofmedicalethics_id = ydyfzb.id LEFT JOIN tb_users_message sq_user ON ydyfzb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ydyfpb.user_id = sp_user.id LEFT JOIN administrative_company my_com ON ydyfzb.apply_company_id = my_com.id WHERE ydyfzb.apply_user_id ={ user_id } AND ydyfzb.state IN ('one', 'two', 'three', 'four')
                UNION ALL 
                SELECT '中层干部外出' as types, gbwc_zb.title as title, CONCAT(date_format(gbwc_zb.create_time, '%Y-%m-%d'), ' ', time_format(gbwc_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when gbwc_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/middle_level_detail.html?id=', gbwc_zb.id) as url, case when gbwc_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_outgoingcadresdata gbwc_zb LEFT JOIN finance_outgoingcadresdata_current_audit_users gbwc_sp ON gbwc_sp.outgoingcadresdata_id=gbwc_zb.id LEFT JOIN tb_users_message sq_user on gbwc_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on gbwc_sp.user_id=sp_user.id WHERE gbwc_zb.apply_user_id={user_id} AND gbwc_zb.state IN ('one', 'two', 'three')
                UNION ALL 
                SELECT '工会经费' as types, ghjf_zb.pay_reason as title, CONCAT(date_format(ghjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(ghjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when ghjf_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/LaborUnionExpensesdetail.html?id=', ghjf_zb.id) as url, case when ghjf_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_laborunionexpenses ghjf_zb LEFT JOIN finance_laborunionexpenses_current_audit_users ghjf_sp ON ghjf_sp.laborunionexpenses_id=ghjf_zb.id LEFT JOIN tb_users_message sq_user on ghjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on ghjf_sp.user_id=sp_user.id WHERE ghjf_zb.apply_user_id={user_id} AND ghjf_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'nine', 'eight')
                UNION ALL 
                SELECT '印章刻制' as types, yzkz_zb.plan_seal_name as title, CONCAT(date_format(yzkz_zb.create_time, '%Y-%m-%d'), ' ', time_format(yzkz_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when yzkz_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/seal_making_detail_view?id=', yzkz_zb.id) as url, case when yzkz_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_sealmaking yzkz_zb LEFT JOIN finance_sealmaking_current_audit_users yzkz_sp ON yzkz_sp.sealmaking_id=yzkz_zb.id LEFT JOIN tb_users_message sq_user on yzkz_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on yzkz_sp.user_id=sp_user.id WHERE yzkz_zb.apply_user_id={user_id} AND yzkz_zb.state IN ('one', 'two', 'three', 'eight')
                UNION ALL 
                SELECT '学科经费' as types, xkjf_zb.pay_reason as title, CONCAT(date_format(xkjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(xkjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when xkjf_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/subject_funding_detail.html?id=', xkjf_zb.id) as url, case when xkjf_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_subjectfunding xkjf_zb LEFT JOIN finance_subjectfunding_current_audit_users xkjf_sp ON xkjf_sp.subjectfunding_id=xkjf_zb.id LEFT JOIN tb_users_message sq_user on xkjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on xkjf_sp.user_id=sp_user.id WHERE xkjf_zb.apply_user_id={user_id} AND xkjf_zb.state IN ('one', 'two', 'three', 'four', 'five', 'eight')
                UNION ALL 
                SELECT '科研经费' as types, kyjf_zb.pay_reason as title, CONCAT(date_format(kyjf_zb.create_time, '%Y-%m-%d'), ' ', time_format(kyjf_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when kyjf_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/research_funding_detail.html?id=', kyjf_zb.id) as url, case when kyjf_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_researchfunding kyjf_zb LEFT JOIN finance_researchfunding_current_audit_users kyjf_sp ON kyjf_sp.researchfunding_id=kyjf_zb.id LEFT JOIN tb_users_message sq_user on kyjf_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on kyjf_sp.user_id=sp_user.id WHERE kyjf_zb.apply_user_id={user_id} AND kyjf_zb.state IN ('one', 'two', 'three', 'four', 'five', 'eight')
                UNION ALL 
                SELECT '快速用印授权' as types, TRIM('"' FROM AA.titles->'$.neirong') AS title, CONCAT(date_format(kssq_zb.create_time, '%Y-%m-%d'), ' ', time_format(kssq_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when kssq_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/QuickAuthorizationDetail.html?id=', kssq_zb.id) as url, case when kssq_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_quickauthorization kssq_zb LEFT JOIN finance_quickauthorization_current_audit_users kssq_sp ON kssq_sp.quickauthorization_id=kssq_zb.id LEFT JOIN tb_users_message sq_user on kssq_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on kssq_sp.user_id=sp_user.id LEFT JOIN ( SELECT JSON_EXTRACT( reason, "$[0]" ) titles, id FROM finance_quickauthorization ) AA ON kssq_zb.id = AA.id WHERE kssq_zb.apply_user_id={user_id} AND kssq_zb.state IN ('one', 'two', 'three', 'four')
                UNION ALL 
                SELECT '图书/报刊/杂志征订' as types, '图书/报刊/杂志征订申请' as title, CONCAT(date_format(tsbk_zb.create_time, '%Y-%m-%d'), ' ', time_format(tsbk_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when tsbk_zb.state = 'eight' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/finance/BookSubscriptionDetail.html?id=', tsbk_zb.id) as url, case when tsbk_zb.state = 'eight' then '修改' else '查看' END as `text` FROM finance_booksubscription tsbk_zb LEFT JOIN finance_booksubscription_current_audit_users tsbk_sp ON tsbk_sp.booksubscription_id=tsbk_zb.id LEFT JOIN tb_users_message sq_user on tsbk_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on tsbk_sp.user_id=sp_user.id WHERE tsbk_zb.apply_user_id={user_id} AND tsbk_zb.state IN ('one', 'two', 'three', 'four')
                UNION ALL 
                SELECT '党建经费' AS types, REPLACE((CASE WHEN djjf_zb.application_reason != '' THEN djjf_zb.application_reason WHEN JSON_EXTRACT (`pay_detail` -> '$[0]', '$.b') != '' THEN JSON_EXTRACT (`pay_detail` -> '$[0]', '$.b') ELSE '党建经费' END), '"', '') AS title, CONCAT(date_format( djjf_zb.create_time, '%Y-%m-%d' ), ' ', time_format( djjf_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN djjf_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/PartyBuildingFundsDetail.html?id=', djjf_zb.id ) AS url, CASE WHEN djjf_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM finance_partybuilding djjf_zb LEFT JOIN finance_partybuilding_current_audit_users djjf_sp ON djjf_sp.partybuilding_id = djjf_zb.id LEFT JOIN tb_users_message sq_user ON djjf_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON djjf_sp.user_id = sp_user.id WHERE djjf_zb.apply_user_id = {user_id} AND djjf_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'eight')
                UNION ALL 
                SELECT '项目审计送审申请' AS types, djjf_zb.work_name AS title, CONCAT(date_format( djjf_zb.create_time, '%Y-%m-%d' ), ' ', time_format( djjf_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by,	sq_user.department AS department, CASE WHEN djjf_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/finance/object_audit_detail_view?id=', djjf_zb.id ) AS url, CASE WHEN djjf_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM finance_objectaudit djjf_zb LEFT JOIN finance_objectaudit_current_audit_users djjf_sp ON djjf_sp.objectaudit_id = djjf_zb.id LEFT JOIN tb_users_message sq_user ON djjf_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON djjf_sp.user_id = sp_user.id WHERE djjf_zb.apply_user_id={user_id} AND djjf_zb.state IN ('one','two','eight')
                UNION ALL 
                SELECT '服务采购' AS types, fwcg_zb.ApplicationReason AS title, CONCAT(date_format( fwcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( fwcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by,	sq_user.department AS department, CASE WHEN fwcg_zb.state = 'six' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/ServiceProcurementDetail.html?id=', fwcg_zb.id ) AS url, CASE WHEN fwcg_zb.state = 'six' THEN '修改' ELSE '查看' END AS `text` FROM logistics_purchasingrequisition fwcg_zb LEFT JOIN logistics_purchasingrequisition_current_audit_users fwcg_sp ON fwcg_sp.purchasingrequisition_id = fwcg_zb.id LEFT JOIN tb_users_message sq_user ON fwcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON fwcg_sp.user_id = sp_user.id WHERE fwcg_zb.apply_user_id={user_id} AND fwcg_zb.state IN ('one','two','three', 'four', 'six')
                UNION ALL 
                SELECT '货物采购' AS types, hwcg_zb.PurchaseReason AS title, CONCAT(date_format( hwcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( hwcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by,	sq_user.department AS department, CASE WHEN hwcg_zb.state = 'six' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/GoodsProcureDetail.html?id=', hwcg_zb.id ) AS url, CASE WHEN hwcg_zb.state = 'six' THEN '修改' ELSE '查看' END AS `text` FROM logistics_goodsprocure hwcg_zb LEFT JOIN logistics_goodsprocure_current_audit_users hwcg_sp ON hwcg_sp.goodsprocure_id = hwcg_zb.id LEFT JOIN tb_users_message sq_user ON hwcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hwcg_sp.user_id = sp_user.id WHERE hwcg_zb.apply_user_id={user_id} AND hwcg_zb.state IN ('one','two','three', 'four', 'six')
                UNION ALL
				SELECT '维修改造' AS types, wxgz_zb.ApplicationReason AS title, CONCAT(date_format(wxgz_zb.create_time, '%Y-%m-%d' ), ' ', time_format(wxgz_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wxgz_zb.state = 'six' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/MaintenanceRenovationDetail.html?id=', wxgz_zb.id ) AS url, CASE WHEN wxgz_zb.state = 'six' THEN '修改' ELSE '查看' END AS `text` FROM logistics_maintenancerenovation wxgz_zb LEFT JOIN logistics_maintenancerenovation_current_audit_users wxgz_sp ON wxgz_sp.maintenancerenovation_id = wxgz_zb.id LEFT JOIN tb_users_message sq_user ON wxgz_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wxgz_sp.user_id = sp_user.id WHERE wxgz_zb.apply_user_id ={ user_id } AND wxgz_zb.state IN ( 'one', 'two', 'three', 'four', 'six' )
                UNION ALL
				SELECT '计算机及相关设备购置' AS types, jsjcg_zb.ApplicationReason AS title, CONCAT(date_format(jsjcg_zb.create_time, '%Y-%m-%d' ), ' ', time_format(jsjcg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jsjcg_zb.state = 'six' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/ComputerDeviceDetail.html?id=', jsjcg_zb.id ) AS url, CASE WHEN jsjcg_zb.state = 'six' THEN '修改' ELSE '查看' END AS `text` FROM logistics_computerdevice jsjcg_zb LEFT JOIN logistics_computerdevice_current_audit_users jsjcg_sp ON jsjcg_sp.computerdevice_id = jsjcg_zb.id LEFT JOIN tb_users_message sq_user ON jsjcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jsjcg_sp.user_id = sp_user.id WHERE jsjcg_zb.apply_user_id ={ user_id } AND jsjcg_zb.state IN ( 'one', 'two', 'three', 'four', 'six' )
                UNION ALL
                SELECT '招标采购项目' AS types, zbxm_zb.ApplicationReason AS title, CONCAT(date_format( zbxm_zb.create_time, '%Y-%m-%d' ), ' ', time_format( zbxm_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zbxm_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/BiddingProcurementProjectDetail.html?id=', zbxm_zb.id ) AS url, CASE WHEN zbxm_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM logistics_biddingprocurementproject zbxm_zb LEFT JOIN logistics_biddingprocurementproject_current_audit_users zbxm_sp ON zbxm_sp.biddingprocurementproject_id = zbxm_zb.id LEFT JOIN tb_users_message sq_user ON zbxm_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zbxm_sp.user_id = sp_user.id WHERE zbxm_zb.apply_user_id ={ user_id } AND zbxm_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'eight' )
                UNION ALL
                SELECT '招标结果汇报会签' AS types, zbhq_zb.entry_name AS title, CONCAT(date_format( zbhq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( zbhq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zbhq_zb.state = 'eight' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/logistics/tendering_signing_detail.html?id=', zbhq_zb.id ) AS url, CASE WHEN zbhq_zb.state = 'eight' THEN '修改' ELSE '查看' END AS `text` FROM logistics_tenderingsigning zbhq_zb LEFT JOIN logistics_tenderingsigning_current_audit_users zbhq_sp ON zbhq_sp.tenderingsigning_id = zbhq_zb.id LEFT JOIN tb_users_message sq_user ON zbhq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zbhq_sp.user_id = sp_user.id WHERE zbhq_zb.apply_user_id ={ user_id } AND zbhq_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'eight' )
                UNION ALL
                SELECT '短信审批' AS types, dxsp_zb.reason AS title, CONCAT(date_format( dxsp_zb.create_time, '%Y-%m-%d' ), ' ', time_format( dxsp_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN dxsp_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/message_approval_detail.html?id=', dxsp_zb.id ) AS url, CASE WHEN dxsp_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_shortmessageapproval dxsp_zb LEFT JOIN supervision_inspection_shortmessageapproval_current_audit_users dxsp_sp ON dxsp_sp.shortmessageapproval_id = dxsp_zb.id LEFT JOIN tb_users_message sq_user ON dxsp_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON dxsp_sp.user_id = sp_user.id WHERE dxsp_zb.apply_user_id ={ user_id } AND dxsp_zb.state IN ( 'one', 'two', 'three', 'refuse')
                UNION ALL
                SELECT '流程节点修改' AS types, jdxg_zb.reason AS title, CONCAT(date_format( jdxg_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jdxg_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jdxg_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/process_modification_detail.html?id=', jdxg_zb.id ) AS url, CASE WHEN jdxg_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_flowmodify jdxg_zb LEFT JOIN supervision_inspection_flowmodify_current_audit_users jdxg_sp ON jdxg_sp.flowmodify_id = jdxg_zb.id LEFT JOIN tb_users_message sq_user ON jdxg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jdxg_sp.user_id = sp_user.id WHERE jdxg_zb.apply_user_id ={ user_id } AND jdxg_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'refuse' )
                UNION ALL
                SELECT '问责申请' AS types, work_table.job_source AS title, CONCAT(date_format( wzsq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wzsq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, '审核中' AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/accountability_detail.html?id=', wzsq_zb.id ) AS url, '查看' AS `text` FROM supervision_inspection_initiateaccountability wzsq_zb LEFT JOIN supervision_inspection_initiateaccountability_current_audit_f16f wzsq_sp ON wzsq_sp.initiateaccountability_id = wzsq_zb.id LEFT JOIN supervision_inspection_worksupervisehandle work_table ON wzsq_zb.work_id_id = work_table.id LEFT JOIN tb_users_message sq_user ON wzsq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wzsq_sp.user_id = sp_user.id WHERE wzsq_zb.apply_user_id ={ user_id } AND wzsq_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'ten')
                UNION ALL
                SELECT '委员会议题' AS types, wyhyt_zb.topic_name AS title, CONCAT(date_format( wyhyt_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wyhyt_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wyhyt_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CASE WHEN wyhyt_zb.state = 'refuse' THEN CONCAT( '/supervision-inspection/committee_topics_modify.html?id=', wyhyt_zb.id ) ELSE CONCAT( '/supervision-inspection/committee_topics_detail.html?id=', wyhyt_zb.id ) END AS url, CASE WHEN wyhyt_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_committeetopics wyhyt_zb LEFT JOIN supervision_inspection_committeetopics_current_audit_users wyhyt_sp ON wyhyt_sp.committeetopics_id = wyhyt_zb.id LEFT JOIN tb_users_message sq_user ON wyhyt_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wyhyt_sp.user_id = sp_user.id WHERE wyhyt_zb.apply_user_id ={ user_id } AND wyhyt_zb.state IN ('zero', 'one', 'two', 'three', 'refuse' )
                UNION ALL
                SELECT '委员会纪要' AS types, wyhjy_zb.conference_memo_text as title, CONCAT(date_format( wyhjy_zb.create_time, '%Y-%m-%d' ), ' ', time_format( wyhjy_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN wyhjy_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/summary_application_detail.html?id=', wyhjy_zb.id ) AS url, CASE WHEN wyhjy_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_committeeminutes wyhjy_zb LEFT JOIN supervision_inspection_committeeminutes_current_audit_users wyhjy_sp ON wyhjy_sp.committeeminutes_id = wyhjy_zb.id LEFT JOIN tb_users_message sq_user ON wyhjy_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON wyhjy_sp.user_id = sp_user.id WHERE wyhjy_zb.apply_user_id = { user_id } AND wyhjy_zb.state IN ('zero', 'one', 'two', 'three', 'four', 'refuse' )
                UNION ALL
                SELECT '行政总值班调班申请' AS types, tbsq_zb.shift_change_reason AS title, CONCAT(date_format( tbsq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( tbsq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN tbsq_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/supervision-inspection/shift_change_detail.html?id=', tbsq_zb.id ) AS url, CASE WHEN tbsq_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_shiftadjustment tbsq_zb LEFT JOIN supervision_inspection_shiftadjustment_current_audit_users tbsq_sp ON tbsq_sp.shiftadjustment_id = tbsq_zb.id LEFT JOIN tb_users_message sq_user ON tbsq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON tbsq_sp.user_id = sp_user.id WHERE tbsq_zb.apply_user_id ={ user_id } AND tbsq_zb.state IN ('one', 'two', 'three', 'four', 'five', 'refuse')
                UNION ALL
                SELECT '会议请假' AS types, hyqj_zb.reason AS title, CONCAT(date_format( hyqj_zb.create_time, '%Y-%m-%d' ), ' ', time_format( hyqj_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_com.`name` AS department, CASE WHEN hyqj_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/meetingleavedetail.html?id=', hyqj_zb.id ) AS url, CASE WHEN hyqj_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM supervision_inspection_meetingroomleave hyqj_zb LEFT JOIN supervision_inspection_meetingroomleave_current_audit_users hyqj_sp ON hyqj_sp.meetingroomleave_id = hyqj_zb.id LEFT JOIN tb_users_message sq_user ON hyqj_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hyqj_sp.user_id = sp_user.id LEFT JOIN administrative_company sq_com ON hyqj_zb.company_id = sq_com.id WHERE hyqj_zb.apply_user_id ={ user_id } AND hyqj_zb.state IN ( 'one', 'two', 'three', 'four', 'refuse' )
                UNION ALL
                SELECT '数据外导' AS types, sjwd_zb.application_reason AS title, CONCAT(date_format( sjwd_zb.create_time, '%Y-%m-%d' ), ' ', time_format( sjwd_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN sjwd_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/finance/data_export_detail.html?id=', sjwd_zb.id ) AS url, CASE WHEN sjwd_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM finance_confidentialdataexport sjwd_zb LEFT JOIN finance_confidentialdataexport_current_audit_users sjwd_sp ON sjwd_sp.confidentialdataexport_id = sjwd_zb.id LEFT JOIN tb_users_message sq_user ON sjwd_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON sjwd_sp.user_id = sp_user.id WHERE sjwd_zb.apply_user_id ={ user_id } AND sjwd_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'refuse' )
                UNION ALL
                SELECT '公务(外宾)接待事前审批' AS types, sqjd_zb.reception_reason AS title, CONCAT(date_format(sqjd_zb.create_time, '%Y-%m-%d' ), ' ', time_format(sqjd_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN sqjd_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/official_business_reception_detail.html?id=', sqjd_zb.id ) AS url, CASE WHEN sqjd_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM newflowlogic_beforehandreception sqjd_zb LEFT JOIN newflowlogic_beforehandreception_current_audit_users sqjd_sp ON sqjd_sp.beforehandreception_id = sqjd_zb.id LEFT JOIN tb_users_message sq_user ON sqjd_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON sqjd_sp.user_id = sp_user.id WHERE sqjd_zb.apply_user_id ={ user_id } AND sqjd_zb.state IN ( 'one', 'two', 'three', 'refuse')
                UNION ALL
                SELECT '公务(外宾)接待清单审批' AS types, jdqd_zb.official_interaction AS title, CONCAT(date_format( jdqd_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jdqd_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jdqd_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/new-flow-logic/reception_checklist_detail.html?id=', jdqd_zb.id ) AS url, CASE WHEN jdqd_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM newflowlogic_receptionchecklist jdqd_zb LEFT JOIN newflowlogic_receptionchecklist_current_audit_users jdqd_sp ON jdqd_sp.receptionchecklist_id = jdqd_zb.id LEFT JOIN tb_users_message sq_user ON jdqd_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jdqd_sp.user_id = sp_user.id WHERE jdqd_zb.apply_user_id ={ user_id } AND jdqd_zb.state IN ('one', 'two', 'refuse')
                UNION ALL
                SELECT '职工出国(境)审批' AS types, zgcg_zb.application_reason AS title, CONCAT(date_format(zgcg_zb.create_time, '%Y-%m-%d'), ' ', time_format(zgcg_zb.create_time, '%H:%i')) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN zgcg_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/new-flow-logic/employees_abroad_detail.html?id=', zgcg_zb.id) AS url, CASE WHEN zgcg_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM newflowlogic_employeesabroad zgcg_zb LEFT JOIN newflowlogic_employeesabroad_current_audit_users zgcg_sp ON zgcg_sp.employeesabroad_id = zgcg_zb.id LEFT JOIN tb_users_message sq_user ON zgcg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON zgcg_sp.user_id = sp_user.id WHERE zgcg_zb.apply_user_id ={ user_id } AND zgcg_zb.state IN ('one', 'two', 'three', 'four', 'five', 'refuse')
                UNION ALL
                SELECT '基建维修改造' AS types, jjwx_zb.reason AS title, CONCAT(date_format( jjwx_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jjwx_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jjwx_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/infrastructure-process/InfrastructureRenovationDetail.html?id=', jjwx_zb.id ) AS url, CASE WHEN jjwx_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM infrastructure_process_infrastructuremaintenance jjwx_zb LEFT JOIN infrastructure_process_infrastructuremaintenance_current_aud18d7 jjwx_sp ON jjwx_sp.infrastructuremaintenance_id = jjwx_zb.id LEFT JOIN tb_users_message sq_user ON jjwx_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jjwx_sp.user_id = sp_user.id WHERE jjwx_zb.apply_user_id ={ user_id } AND jjwx_zb.state IN ('one', 'two', 'three', 'four', 'refuse')
                UNION ALL
                SELECT '基建项目专业服务' AS types, jjxm_zb.reason AS title, CONCAT(date_format( jjxm_zb.create_time, '%Y-%m-%d' ), ' ', time_format( jjxm_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jjxm_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/infrastructure-process/ProfessionalServicesDetail.html?id=', jjxm_zb.id ) AS url, CASE WHEN jjxm_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM infrastructure_process_professionalservices jjxm_zb LEFT JOIN infrastructure_process_professionalservices_current_audit_users jjxm_sp ON jjxm_sp.professionalservices_id = jjxm_zb.id LEFT JOIN tb_users_message sq_user ON jjxm_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jjxm_sp.user_id = sp_user.id WHERE jjxm_zb.apply_user_id ={ user_id } AND jjxm_zb.state IN ('one', 'two', 'three', 'refuse')
                UNION ALL
                SELECT '体检科支援加班补助' AS types, '体检科支援加班补助' AS title, CONCAT(date_format(jbbz_zb.create_time, '%Y-%m-%d'), ' ', time_format( jbbz_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN jbbz_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/payment-management/OvertimeAllowanceDetail.html?id=', jbbz_zb.id) AS url, CASE WHEN jbbz_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM payment_management_supportsubsidies jbbz_zb LEFT JOIN payment_management_supportsubsidies_current_audit_users jbbz_sp ON jbbz_sp.supportsubsidies_id = jbbz_zb.id LEFT JOIN tb_users_message sq_user ON jbbz_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON jbbz_sp.user_id = sp_user.id WHERE jbbz_zb.apply_user_id ={ user_id } AND jbbz_zb.state IN ('one', 'two', 'three', 'refuse')
                UNION ALL
                SELECT '工会用印申请' AS types, ghyy_zb.reason AS title, CONCAT(date_format( ghyy_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghyy_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghyy_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/union-process/PrintingProcessDetail.html?id=', ghyy_zb.id) AS url, CASE WHEN ghyy_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_officialseal ghyy_zb LEFT JOIN union_process_officialseal_current_audit_users ghyy_sp ON ghyy_sp.officialseal_id = ghyy_zb.id LEFT JOIN tb_users_message sq_user ON ghyy_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghyy_sp.user_id = sp_user.id WHERE ghyy_zb.apply_user_id ={ user_id } AND ghyy_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'refuse')
                UNION ALL
                SELECT '工会经济合同会签' AS types, ghhthq_zb.contract_name AS title, CONCAT(date_format( ghhthq_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghhthq_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghhthq_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/EconomicSigningDetail.html?id=', ghhthq_zb.id ) AS url, CASE WHEN ghhthq_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_economiccountersign ghhthq_zb LEFT JOIN union_process_economiccountersign_current_audit_users ghhthq_sp ON ghhthq_sp.economiccountersign_id = ghhthq_zb.id LEFT JOIN tb_users_message sq_user ON ghhthq_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghhthq_sp.user_id = sp_user.id WHERE ghhthq_zb.apply_user_id ={ user_id } AND ghhthq_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'refuse' )
                UNION ALL
                SELECT '工会付款流程' AS types, ghfk_zb.reason AS title, CONCAT(date_format( ghfk_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghfk_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghfk_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/PayFlowDetail.html?id=', ghfk_zb.id ) AS url, CASE WHEN ghfk_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_paymentprocess ghfk_zb LEFT JOIN union_process_paymentprocess_current_audit_users ghfk_sp ON ghfk_sp.paymentprocess_id = ghfk_zb.id LEFT JOIN tb_users_message sq_user ON ghfk_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghfk_sp.user_id = sp_user.id WHERE ghfk_zb.apply_user_id ={ user_id } AND ghfk_zb.state IN ( 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'refuse' )
                UNION ALL
                SELECT '工会活动审批' AS types, ghsqsp_zb.reason AS title, CONCAT(date_format( ghsqsp_zb.create_time, '%Y-%m-%d' ), ' ', time_format( ghsqsp_zb.create_time, '%H:%i' )) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghsqsp_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/PreApprovalDetail.html?id=', ghsqsp_zb.id ) AS url, CASE WHEN ghsqsp_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_eventapproval ghsqsp_zb LEFT JOIN union_process_eventapproval_current_audit_users ghsqsp_sp ON ghsqsp_sp.eventapproval_id = ghsqsp_zb.id LEFT JOIN tb_users_message sq_user ON ghsqsp_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON ghsqsp_sp.user_id = sp_user.id WHERE ghsqsp_zb.apply_user_id ={ user_id } AND ghsqsp_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'refuse')
                UNION ALL
                SELECT '工会物资申购' AS types, ghwzsg_zb.reason AS title, CONCAT(date_format(ghwzsg_zb.create_time, '%Y-%m-%d' ), ' ', time_format(ghwzsg_zb.create_time, '%H:%i')) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN ghwzsg_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT( '/union-process/GoodsSubscribeDetail.html?id=', ghwzsg_zb.id ) AS url, CASE WHEN ghwzsg_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_materialsapproval ghwzsg_zb LEFT JOIN union_process_materialsapproval_current_audit_users hwzsg_sp ON hwzsg_sp.materialsapproval_id = ghwzsg_zb.id LEFT JOIN tb_users_message sq_user ON ghwzsg_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON hwzsg_sp.user_id = sp_user.id WHERE ghwzsg_zb.apply_user_id ={ user_id } AND ghwzsg_zb.state IN ('one', 'two', 'three', 'four', 'five', 'six', 'refuse')
                UNION ALL
                SELECT '门诊排班调整' AS types, mzpb_zb.stop_reason AS title, CONCAT(date_format(mzpb_zb.create_time, '%Y-%m-%d'), ' ', time_format(mzpb_zb.create_time, '%H:%i')) AS create_time, sq_user.real_name AS create_by, sq_user.department AS department, CASE WHEN mzpb_zb.state = 'refuse' THEN '退回' ELSE '审核中' END AS node, sp_user.real_name AS approved, CONCAT('/union-process/SchedulingAdjustmentDetail.html?id=', mzpb_zb.id) AS url, CASE WHEN mzpb_zb.state = 'refuse' THEN '修改' ELSE '查看' END AS `text` FROM union_process_outpatientscheduling mzpb_zb LEFT JOIN union_process_outpatientscheduling_current_audit_users mzpb_sp ON mzpb_sp.outpatientscheduling_id = mzpb_zb.id LEFT JOIN tb_users_message sq_user ON mzpb_zb.apply_user_id = sq_user.id LEFT JOIN tb_users_message sp_user ON mzpb_sp.user_id = sp_user.id WHERE mzpb_zb.apply_user_id ={ user_id } AND mzpb_zb.state IN ('one', 'two', 'refuse')
                UNION ALL
                SELECT zdy_wj.module as types, zdy_wj.`name` as title, CONCAT(date_format(zdy_zb.create_time, '%Y-%m-%d'), ' ', time_format(zdy_zb.create_time, '%H:%i')) as create_time, sq_user.real_name as create_by, sq_user.department as department, case when zdy_zb.state = 'four' then '退回' else '审核中' END as node, sp_user.real_name as approved, CONCAT('/personal-center/CustomProcessDetail.html?id=', zdy_zb.id) as url, case when zdy_zb.state = 'four' then '修改' else '查看' END as `text` FROM system_setup_lowcodebill zdy_zb LEFT JOIN system_setup_lowcodebill_current_audit_users zdy_sp ON zdy_sp.lowcodebill_id=zdy_zb.id LEFT JOIN tb_users_message sq_user on zdy_zb.apply_user_id=sq_user.id LEFT JOIN tb_users_message sp_user on zdy_sp.user_id=sp_user.id LEFT JOIN system_setup_customerform zdy_wj ON zdy_zb.customer_form_id=zdy_wj.id WHERE zdy_zb.apply_user_id={user_id} AND zdy_zb.state='one'
                ) base where 1=1 ORDER BY create_time DESC
                """
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
            data_list = []
            for i in select_data:
                data_list.append({
                    'types': i[0], 'title': i[1], 'create_time': i[2], 'create_by': i[3], 'department': i[4], "reviewer": i[6],
                    'node': i[5], 'approved': f'<a href="javascript:;" style="color: red;">{i[6]}</a>' if i[6] else "", 'url': i[7], 'text': i[8]
                })
            return data_list

    def my_shelving(self, user_id, user_name):
        """我的搁置"""
        select_sql = f"""
        SELECT * FROM (SELECT '公文管理' AS Types, '上级来文' AS classification, COUNT(A.id) counts FROM administrative_officialdocuments_current_audit_users A LEFT JOIN administrative_officialdocuments B ON A.officialdocuments_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '外部来函' AS classification, COUNT(A.id) counts FROM administrative_correspondence_current_audit_users A LEFT JOIN administrative_correspondence B ON A.correspondence_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '公告管理' AS Types, '通知公告' AS classification, COUNT(B.id) counts FROM announcements_notice A LEFT JOIN announcements_auditrecord B ON A.id=B.notice_id_id WHERE A.audit_people_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '车辆管理' AS Types, '车辆申请' as classification, COUNT(id) counts FROM administrative_vehicleapply WHERE current_audit_user_id={user_id} AND state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '党委公文' as classification, COUNT(O.id) counts FROM administrative_conferencememo_current_audit_users O LEFT JOIN administrative_conferencememo P ON O.conferencememo_id=P.id WHERE O.user_id={user_id} AND P.type='g' AND P.state='shelve'
        UNION ALL
        SELECT '会议室管理' AS Types, '会议室申请' as classification, COUNT(id) counts FROM personal_center_conferenceroomapplication WHERE audit_people_id={user_id} AND state='shelve'
        UNION ALL
        SELECT '议题管理' AS Types, '党委会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='db' AND state='shelve'
        UNION ALL
        SELECT '议题管理' AS Types, '行政例会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='xz' AND state='shelve'
		UNION ALL
        SELECT '议题管理' AS Types, '院长办公会议题' as classification, COUNT(id) counts FROM administrative_topics WHERE current_audit_user='{user_name}' AND type='yb' AND state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '党委会议纪要' as classification, COUNT(C.id) counts FROM administrative_conferencememo_current_audit_users C LEFT JOIN administrative_conferencememo D ON C.conferencememo_id=D.id WHERE C.user_id={user_id} AND D.type='a' AND D.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '行政例会简报' as classification, COUNT(K.id) counts FROM administrative_conferencememo_current_audit_users K LEFT JOIN administrative_conferencememo L ON K.conferencememo_id=L.id WHERE K.user_id={user_id} AND L.type='e' AND L.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '党委专题会议纪要' as classification, COUNT(G.id) counts FROM administrative_conferencememo_current_audit_users G LEFT JOIN administrative_conferencememo H ON G.conferencememo_id=H.id WHERE G.user_id={user_id} AND H.type='c' AND H.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医发)' as classification, COUNT(M.id) counts FROM administrative_conferencememo_current_audit_users M LEFT JOIN administrative_conferencememo N ON M.conferencememo_id=N.id WHERE M.user_id={user_id} AND N.type='f' AND N.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '行政公文(京医文)' as classification, COUNT(Q.id) counts FROM administrative_conferencememo_current_audit_users Q LEFT JOIN administrative_conferencememo R ON Q.conferencememo_id=R.id WHERE Q.user_id={user_id} AND R.type='h' AND R.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会会议纪要' as classification, COUNT(E.id) counts FROM administrative_conferencememo_current_audit_users E LEFT JOIN administrative_conferencememo F ON E.conferencememo_id=F.id WHERE E.user_id={user_id} AND F.type='b' AND F.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '院长办公会专题会议纪要' as classification, COUNT(I.id) counts FROM administrative_conferencememo_current_audit_users I LEFT JOIN administrative_conferencememo J ON I.conferencememo_id=J.id WHERE I.user_id=66 AND J.type='d' AND J.state='shelve'
        UNION ALL
        SELECT '公文管理' AS Types, '京医团总支发文' as classification, COUNT(I.id) counts FROM administrative_conferencememo_current_audit_users I LEFT JOIN administrative_conferencememo J ON I.conferencememo_id=J.id WHERE I.user_id={user_id} AND J.type='i' AND J.state='shelve'
        UNION ALL
        SELECT '大型活动' AS Types, '大型活动报备' as classification, COUNT(I.id) counts FROM administrative_gatheringapply I LEFT JOIN administrative_gatheringapply_current_audit_users J ON J.gatheringapply_id=I.id WHERE J.user_id={user_id} AND I.state='shelve'
        UNION ALL
        SELECT '医德医风' AS Types, '医德医风考评' as classification, COUNT(A.id) counts FROM medical_ethics_evaluationofmedicalethics_current_audit_users A LEFT JOIN medical_ethics_evaluationofmedicalethics B ON A.evaluationofmedicalethics_id=B.id WHERE user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '用印审批' AS Types, '用印申请' as classification, COUNT(A.sealapply_id) counts FROM personal_center_sealapply_current_audit_users A LEFT JOIN personal_center_sealapply B ON A.sealapply_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '固定资产/维修维保付款' as classification, COUNT(A.fixedassets_id) counts FROM personal_center_fixedassets_current_audit_users A LEFT JOIN personal_center_fixedassets B ON A.fixedassets_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅申请' as classification, COUNT(A.travelapply_id) counts FROM finance_travelapply_current_audit_users A LEFT JOIN finance_travelapply B ON A.travelapply_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '材料付款' as classification, COUNT(A.medicalmaterials_id) counts FROM finance_medicalmaterials_current_audit_users A LEFT JOIN finance_medicalmaterials B ON A.medicalmaterials_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '一般付款' as classification, COUNT(A.generalfinance_id) counts FROM finance_generalfinance_current_audit_users A LEFT JOIN finance_generalfinance B ON A.generalfinance_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '餐补付款' as classification, COUNT(A.nutritionalmeals_id) counts FROM finance_nutritionalmeals_current_audit_users A LEFT JOIN finance_nutritionalmeals B ON A.nutritionalmeals_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '临床管理' AS Types, '新增医疗服务项目' as classification, COUNT(A.newmedicalservices_id) counts FROM finance_newmedicalservices_current_audit_users A LEFT JOIN finance_newmedicalservices B ON A.newmedicalservices_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '付款审批' AS Types, '合同付款' as classification, COUNT(A.logisticsoffice_id) counts FROM finance_logisticsoffice_current_audit_users A LEFT JOIN finance_logisticsoffice B ON A.logisticsoffice_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '人事审批' AS Types, '请假申请' as classification, COUNT(A.leaverequest_id) counts FROM finance_leaverequest_current_audit_users A LEFT JOIN finance_leaverequest B ON A.leaverequest_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '临床管理' AS Types, '手术分级授权' as classification, COUNT(A.surgicalgrading_id) counts FROM finance_surgicalgrading_current_audit_users A LEFT JOIN finance_surgicalgrading B ON A.surgicalgrading_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
         UNION ALL
        SELECT '临床管理' AS Types, '临床医师单独执业资格' as classification, COUNT(A.solopracticeapply_id) counts FROM finance_solopracticeapply_current_audit_users A LEFT JOIN finance_solopracticeapply B ON A.solopracticeapply_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '历史数据管理' AS Types, '经济合同会签' as classification, COUNT(A.businesscontract_id) counts FROM finance_businesscontract_current_audit_users A LEFT JOIN finance_businesscontract B ON A.businesscontract_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '差旅审批' AS Types, '差旅报销' as classification, COUNT(A.travelreimbursement_id) counts FROM finance_travelreimbursement_current_audit_users A LEFT JOIN finance_travelreimbursement B ON A.travelreimbursement_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '人事审批' AS Types, '离职申请' as classification, COUNT(A.dimission_id) counts FROM finance_dimission_current_audit_users A LEFT JOIN finance_dimission B ON A.dimission_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '差旅审批' AS Types, '中层干部外出' as classification, COUNT(A.outgoingcadresdata_id) counts FROM finance_outgoingcadresdata_current_audit_users A LEFT JOIN finance_outgoingcadresdata B ON A.outgoingcadresdata_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '历史数据管理' AS Types, '工会经费' as classification, COUNT(A.laborunionexpenses_id) counts FROM finance_laborunionexpenses_current_audit_users A LEFT JOIN finance_laborunionexpenses B ON A.laborunionexpenses_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL 
        SELECT '用印审批' AS Types, '印章刻制' as classification, COUNT(A.sealmaking_id) counts FROM finance_sealmaking_current_audit_users A LEFT JOIN finance_sealmaking B ON A.sealmaking_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '学科经费' as classification, COUNT(A.subjectfunding_id) counts FROM finance_subjectfunding_current_audit_users A LEFT JOIN finance_subjectfunding B ON A.subjectfunding_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '科研经费' as classification, COUNT(A.researchfunding_id) counts FROM finance_researchfunding_current_audit_users A LEFT JOIN finance_researchfunding B ON A.researchfunding_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '用印审批' AS Types, '快速用印授权' as classification, COUNT(A.quickauthorization_id) counts FROM finance_quickauthorization_current_audit_users A LEFT JOIN finance_quickauthorization B ON A.quickauthorization_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '后勤管理' AS Types, '图书/报刊/杂志征订' as classification, COUNT(A.booksubscription_id) counts FROM finance_booksubscription_current_audit_users A LEFT JOIN finance_booksubscription B ON A.booksubscription_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '付款审批' AS Types, '党建经费' as classification, COUNT(A.partybuilding_id) counts FROM finance_partybuilding_current_audit_users A LEFT JOIN finance_partybuilding B ON A.partybuilding_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '项目管理' AS Types, '项目审计送审申请' as classification, COUNT(A.objectaudit_id) counts FROM finance_objectaudit_current_audit_users A LEFT JOIN finance_objectaudit B ON A.objectaudit_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '后勤管理' AS Types, '服务采购' as classification, COUNT(A.purchasingrequisition_id) counts FROM logistics_purchasingrequisition_current_audit_users A LEFT JOIN logistics_purchasingrequisition B ON A.purchasingrequisition_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '后勤管理' AS Types, '货物采购' as classification, COUNT(A.goodsprocure_id) counts FROM logistics_goodsprocure_current_audit_users A LEFT JOIN logistics_goodsprocure B ON A.goodsprocure_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '后勤管理' AS Types, '维修改造' as classification, COUNT(A.maintenancerenovation_id) counts FROM logistics_maintenancerenovation_current_audit_users A LEFT JOIN logistics_maintenancerenovation B ON A.maintenancerenovation_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '网络信息' AS Types, '计算机及相关设备购置' as classification, COUNT(A.computerdevice_id) counts FROM logistics_computerdevice_current_audit_users A LEFT JOIN logistics_computerdevice B ON A.computerdevice_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT '项目管理' AS Types, '招标采购项目' as classification, COUNT(A.id) counts FROM logistics_biddingprocurementproject_current_audit_users A LEFT JOIN logistics_biddingprocurementproject B ON A.biddingprocurementproject_id=B.id WHERE A.user_id={user_id} AND B.state='shelve'
        UNION ALL
        SELECT b.module AS Types, b.`name` as classification, 0 counts FROM system_setup_lowcodebill a left join system_setup_customerform b on a.customer_form_id = b.id left join system_setup_lowcodebill_current_audit_users m on m.lowcodebill_id = a.id WHERE m.user_id={user_id} group by Types, classification
        ) Z ORDER BY counts DESC
        """
        with connection.cursor() as cursor:
            cursor.execute(select_sql)
            select_data = cursor.fetchall()
            return select_data


if __name__ == '__main__':
    insert_data = [[7, 'JYYB-DZB-2022-01', '2022-04-05 21:46', '议题测试提交-院办', '党政办公室', '孔智慧', ''], [8, 'JYYB-DZB-2022-02', '2022-04-07 17:12', '测试议题目录', '党政办公室', '孔智慧', '邓艳芳, 邓可, 郭芳, 陶思月']]
    excel_name = r"D:\Users\hhr\PycharmProjects\hospitalisoa\media\Issue_information\2022年第1次院长办公会-会议目录.xlsx"
    create_excel().excel_write(insert_data, excel_name, "2022年第1次院长办公会")
